Replying over a socket

Scott Slaugh xslaugh at gmail.com
Mon May 9 13:07:13 EDT 2005


I am trying to set up a program where a client requests some information 
from a server, which is then sent back to the client over the same socket. I 
tried using this script in the server:

on startListen
accept connections on port 8080 with message newRequest
end startListen

on newRequest theSocket
read from socket theSocket for one line
answer it
write "message received" to socket theSocket
close socket theSocket
end newRequest

In the client, I put this in a button:

on mouseUp
open socket to "1.1.1.1:8080 <http://1.1.1.1:8080>"
write "some request" to socket "1.1.1.1:8080 <http://1.1.1.1:8080>"
read from socket "1.1.1.1:8080 <http://1.1.1.1:8080>" for one line
answer it
close socket "1.1.1.1:8080 <http://1.1.1.1:8080>"
end mouseUp

However, the above script does not work. I end up just getting to blank 
answer boxes on both machines after the sockets time out. I would really 
like to be able to have my request and response go out over the same socket. 
Additionally, I would like the client handler to pause until the response is 
received, since it is acting as a request command. Has anyone done anything 
like this, or know what I need to do to get this working?

Scott Slaugh


More information about the use-livecode mailing list