Asunto: Socket, network, testing and coding
Fecha: 28 de febrero de 2017, 14:27:58 CLST
Hi guys,
Quick question regarding sockets and testing.
I'm trying to implement a simple communication protocol to exchange data (strings) between 2 images and I was wondering what was the easiest way to test/develop my code? I want to be able to do something similar to a chat client between 2 images where none of those 2 images acts as a server. So data can originate from any of those 2 images and both images have to "listen" to each other. Besides, both images would have to transmit/receive on the same port.
1) Is this possible (the way I want to do/test it)?
Yes, you can test it.
2) How do I simulate something like this on a *single* machine running those 2 images?
Something like this:
| listener clientSocket serverSocket |
listener := Socket newTCP.
[ listener listenOn: 0 backlogSize: 4.
clientSocket := Socket newTCP.
clientSocket connectTo: #[127 0 0 1] port: listener localPort.
clientSocket waitForConnectionFor: 1.
serverSocket := listener waitForAcceptFor: 1. ]
ensure: [ listener destroy ].
since then you have client and server socket. You can call it clientOne, clientTwo.
3) Do I need to have one of those 2 images act as a "server��� ?
At least one image has to serve as a server (listen to connections). Maybe you could use a discovery service protocol. I do not have any experience about it.
4) Any helpful tip and/or interesting link to propose?
5) Can you think of any simple code or example I could look at to understand what I need to do?
You can check an example here: TRNLog exampleOpenChatWithUserIdUsingTrantor
But you are going to be more interested in testing: TrantorNodeTest
Download it using:
Gofer it
smalltalkhubUser: 'EvanDonahue' project: 'Trantor';
configuration;
loadBleedingEdge.
And maybe Zinc (part of the Pharo image) has also good test examples.
Cheers,
Juraj
-----------------
Beno��t St-Jean
Yahoo! Messenger: bstjean
Twitter: @BenLeChialeux
Pinterest: benoitstjean
Instagram: Chef_Benito
IRC: lamneth
Blogue:
endormitoire.wordpress.com
"A standpoint is an intellectual horizon of radius zero". (A. Einstein)