Sockets
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Sockets
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â€
Blanc
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:
And here is a the script of the server that responds to the client:
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
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
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
Mark
Last edited by Mark on Tue Jan 30, 2007 10:33 pm, edited 1 time in total.
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode