I created two very simple applications to test learning about using sockets to communicate between applications.
I am trying to do this with a single computer.
Server Application
Code: Select all
on mouseUp
accept connections on port 12345 with message "connectionMade"
put "Accepting connections on 12345" & return into field "log"
put the openSockets & return after field "sockList"
end mouseUp
on connectionMade pIPAddress
setSocket pIPAddress;
//put "Connection made:" && pIPAddress
put "connectionMade called:" & pIPAddress & return after field "log"
read from socket pIPAddress with message "gotDBrequest"
end connectionMade
on gotDBrequest pSocket, pData
write "Server got<" & pData & ">" to socket pSocket; //you do this if you just want to echo back what you got.
put pSocket & ":" & pData & return after field "log"
read from socket pSocket with message "doReading"
end gotDBrequest
on doReading pSocket, pData
put short time & pSocket & ":" & pData & return after field "log"
read from socket pSocket with message "doReading"
end doReading
Client Application
Code: Select all
on mouseUp
open socket to "127.0.0.0:12345" with message "clientConnected"
put "trying to open connection" & return after field "log"
end mouseUp
on clientConnected pSocket
setSocket pSocket;
put "got clientConnected call:" & pSocket & return after field "log"
write "got clientConnected call:" & pSocket to socket pSocket with message "connectResponse"
end clientConnected
on connectResponse pSocket, pMsg
put "connectResponse called:" after field "log";
put pSocket & return after field "log";
put pMsg & return after field "log"
end connectResponse
I see the "trying to open connection" message show up.
Then many many minutes later I see the "got clientConnected call" message in the client application.
Then nothing more, ever.
Does not work any better if I have one or both of the applications running inside Livecode or if I build the Apps as standalones and shut down Livecode.
So does this mean for testing socket code you need TWO computers?
Using Livecode 9.6.8 on a Macintosh, latest MacOS
Thanks,
Andrew