Testing client / server sockets possible on a single computer?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Thu Sep 20, 2012 5:11 pm

Testing client / server sockets possible on a single computer?

Post by aetaylorBUSBnWt » Tue Dec 06, 2022 3:37 am

Hi,

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
Then I hit a button in the other application to connect to the server app.

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 "Accepting connections" messge on the server app.
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

Emily-Elizabeth
Posts: 101
Joined: Mon Jan 03, 2022 7:10 pm

Re: Testing client / server sockets possible on a single computer?

Post by Emily-Elizabeth » Tue Dec 06, 2022 4:24 am

Code: Select all

   open socket to "127.0.0.0:12345" with message "clientConnected"
that should be 127.0.0.1 and trying it on the same computer should be fine.

aetaylorBUSBnWt
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 118
Joined: Thu Sep 20, 2012 5:11 pm

Re: Testing client / server sockets possible on a single computer?

Post by aetaylorBUSBnWt » Tue Dec 06, 2022 4:36 am

Argh!

Thanks!

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”