The description of sockets at
http://book.pharo-project.org/book/networking/Socket/ is:

Socket is one of the main networking classes. You can create a new TCP
socket with the message #newTCP.
> 
> This example creates a TCP socket and puts it into listening mode. After a
> client has connected, it reads data from the socket.
> 
> | server client |
> server := Socket newTCP.
> server listenOn: 12345 backlogSize: 4.
> server waitForConnectionFor: 600.
> client := server accept.
> client receiveData
> 

Huh?!  It looks like half the code in this snippet belongs on the server,
and the other half on the client.  I tried:
  Server doit:
    server := Socket newTCP.
    server listenOn: 12345 backlogSize: 4.
    server waitForConnectionFor: 600.
  Client doit:
    server := Socket newTCP.
    server listenOn: 12345 backlogSize: 4.
    server waitForConnectionFor: 600.
    client := server accept.
    client receiveData.
but the server just hung forever.

After flopping around for a while, and checking the swiki, it seemed to be
listenOn:backlogSize: that was the problem.  Everything went well with:
  Server DoIt:
    server := Socket newTCP.
    server listenOn: 8080.
    server waitForConnectionFor: 600.
    server sendData: 'Hello from the server'
  Client PrintIt:
    client := Socket newTCP.
    client connectTo: (NetNameResolver localHostAddress) port: 8080.
    client receiveData.

Anyway, I'd like to have this be clearer, but my knowledge is very basic. 
Also, the class comment for socket reads "...Sockets are the lowest level of
networking object in Squeak and are not normally used directly..." so is
this where we want to direct people first?

Thanks.
Sean
-- 
View this message in context: 
http://forum.world.st/Sockets-in-Pharo-CollaborActive-Book-tp2399361p2399361.html
Sent from the Pharo Smalltalk mailing list archive at Nabble.com.

_______________________________________________
Pharo-project mailing list
Pharo-project@lists.gforge.inria.fr
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to