Page 1 of 1
Sockets
Posted: Thu Jan 18, 2007 5:28 pm
by Blanc
I am a new comer to Revolution (but an old user of Hypercard). Till now I was using Applescript and Eudora to let my stacks communicate with a remote server. I would like to use sockets instead, but tried unsuccessfully to use the “write to socketâ€
Posted: Fri Jan 19, 2007 10:49 am
by Mark
Hi Blanc,
Your script writes to and reads from the sockets, regardless of information being available in the socket. You need an application on the other side, which accepts a connection and replies. This can be an FTP server, a CGI server, etc, but usually it is easier to connect to such servers using a URL, without explicitly opening sockets. If you are making your own protocol, you might indeed want to make your own script that writes to and reads from sockets. Usually, it means that you also write your own server application. An example of this is ChatRev, where you can log in and ask the people there how sockets work :-)
Here is an example of a client script, which connects to a server:
Code: Select all
on foo
-- change the following line as necessary
-- the server ip address before the colon, the port after the colon
put "192.168.0.1:61010" into mySock
open socket mySock
put the result
write "time" & cr to socket mySock
wait 200 millisecs
read from socket mySock until cr with message "gotTime"
end foo
on gotTime theSock,theMsg
beep
answer theMsg
close socket theSock
end gotTime
And here is a the script of the server that responds to the client:
Code: Select all
on startListening
accept connections on port 61010 with message "receiveRequest"
end startListening
on receiveRequest theSock,theMsg
read from socket theSock until cr with message "receiveMessage"
end receiveRequest
on receiveMessage theSock,theMsg
if word 1 to -1 of theMsg is "time" then
write the long date & cr to socket theSock
end if
close socket theSock
end receiveMessage
Just create a client and a server stack. Create a button in the client, which calls the "foo" handler. Create a button in the server, which calls the startListening handler. Open the stacks on two different computers on your local network and press the buttons, the server first. Have fun.
Mark
Posted: Wed Jan 24, 2007 2:10 pm
by Blanc
These client and server scripts were very useful to test that the client side was working correctly. The problem, now solved, lay in the server (an IBM mainframe).
Thanks.