Re: [Pharo-project] Networking problems on Pharo 1.2.1
That is no networking problem. That is just how a tcp server connections work. When you connect from a client to the server, the server has to initialize a new socket to communicate on. Just take a look at what waitForConnectionFor does. Stephan
On 21 Apr 2011, at 12:42, Stephan Eggermont wrote:
That is no networking problem. That is just how a tcp server connections work. When you connect from a client to the server, the server has to initialize a new socket to communicate on. Just take a look at what waitForConnectionFor does.
Stephan
I don't agree, accept is what a server does for a socket that is listening, connecting is what a client does. The code is not as I would write it (it is wrong to create server sockets in a loop). One also has to be careful with multithreading and who is waiting for who. I think the problem might be the #listenOn: I use #listenOn:backlogSize: These are using different primitives. Sven
Thanks all for your comments. On Apr 21, 2011, at 07:13 , Sven Van Caekenberghe wrote:
I think the problem might be the #listenOn: I use #listenOn:backlogSize: These are using different primitives.
I tested with #listenOn:backlogSize: too, with the same result, error on #waitForAcceptFor: . Cheers
Oscar, This is how I would write it, using first SocketStreams (which is better for most users) and then plain Sockets. This works for me on Pharo 1.2.2 and 1.3. HTH, Sven | serverSocket dataSent dataRead clientStream semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientSocket serverStream | clientSocket := serverSocket waitForAcceptFor: 10. serverStream := SocketStream on: clientSocket. dataRead := serverStream upToEnd. serverStream close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. (Delay forMilliseconds: 100) wait. dataSent := 'Hello there!'. clientStream := SocketStream openConnectionToHostNamed: 'localhost' port: 9191. clientStream nextPutAll: dataSent. clientStream close. semaphore wait. self assert: dataSent = dataRead. dataRead | serverSocket clientSocket dataSent dataRead semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientConnectionSocket | clientConnectionSocket := serverSocket waitForAcceptFor: 10. dataRead := clientConnectionSocket receiveData. clientConnectionSocket close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. (Delay forMilliseconds: 100) wait. dataSent := 'Hello there!'. clientSocket := Socket newTCP connectToHostNamed: 'localhost' port: 9191. clientSocket sendData: dataSent. clientSocket close. semaphore wait. self assert: dataSent = dataRead. dataRead On 21 Apr 2011, at 15:04, Oscar E A Callau wrote:
Thanks all for your comments.
On Apr 21, 2011, at 07:13 , Sven Van Caekenberghe wrote:
I think the problem might be the #listenOn: I use #listenOn:backlogSize: These are using different primitives.
I tested with #listenOn:backlogSize: too, with the same result, error on #waitForAcceptFor: .
Cheers
Thank you very much Sven, I think this must be include in the pharo book, because it was hard to find good examples. Cheers. On Apr 21, 2011, at 08:22 , Sven Van Caekenberghe wrote:
Oscar,
This is how I would write it, using first SocketStreams (which is better for most users) and then plain Sockets. This works for me on Pharo 1.2.2 and 1.3.
HTH,
Sven
| serverSocket dataSent dataRead clientStream semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientSocket serverStream | clientSocket := serverSocket waitForAcceptFor: 10. serverStream := SocketStream on: clientSocket. dataRead := serverStream upToEnd. serverStream close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. (Delay forMilliseconds: 100) wait. dataSent := 'Hello there!'. clientStream := SocketStream openConnectionToHostNamed: 'localhost' port: 9191. clientStream nextPutAll: dataSent. clientStream close. semaphore wait. self assert: dataSent = dataRead. dataRead
| serverSocket clientSocket dataSent dataRead semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientConnectionSocket | clientConnectionSocket := serverSocket waitForAcceptFor: 10. dataRead := clientConnectionSocket receiveData. clientConnectionSocket close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. (Delay forMilliseconds: 100) wait. dataSent := 'Hello there!'. clientSocket := Socket newTCP connectToHostNamed: 'localhost' port: 9191. clientSocket sendData: dataSent. clientSocket close. semaphore wait. self assert: dataSent = dataRead. dataRead
On 21 Apr 2011, at 15:04, Oscar E A Callau wrote:
Thanks all for your comments.
On Apr 21, 2011, at 07:13 , Sven Van Caekenberghe wrote:
I think the problem might be the #listenOn: I use #listenOn:backlogSize: These are using different primitives.
I tested with #listenOn:backlogSize: too, with the same result, error on #waitForAcceptFor: .
Cheers
Yes!!!! I forwarded that mail to the network chapter authors. and we will really ask for feedback Stef On Apr 21, 2011, at 4:06 PM, Oscar E A Callau wrote:
Thank you very much Sven, I think this must be include in the pharo book, because it was hard to find good examples.
Cheers.
On Apr 21, 2011, at 08:22 , Sven Van Caekenberghe wrote:
Oscar,
This is how I would write it, using first SocketStreams (which is better for most users) and then plain Sockets. This works for me on Pharo 1.2.2 and 1.3.
HTH,
Sven
| serverSocket dataSent dataRead clientStream semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientSocket serverStream | clientSocket := serverSocket waitForAcceptFor: 10. serverStream := SocketStream on: clientSocket. dataRead := serverStream upToEnd. serverStream close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. (Delay forMilliseconds: 100) wait. dataSent := 'Hello there!'. clientStream := SocketStream openConnectionToHostNamed: 'localhost' port: 9191. clientStream nextPutAll: dataSent. clientStream close. semaphore wait. self assert: dataSent = dataRead. dataRead
| serverSocket clientSocket dataSent dataRead semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientConnectionSocket | clientConnectionSocket := serverSocket waitForAcceptFor: 10. dataRead := clientConnectionSocket receiveData. clientConnectionSocket close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. (Delay forMilliseconds: 100) wait. dataSent := 'Hello there!'. clientSocket := Socket newTCP connectToHostNamed: 'localhost' port: 9191. clientSocket sendData: dataSent. clientSocket close. semaphore wait. self assert: dataSent = dataRead. dataRead
On 21 Apr 2011, at 15:04, Oscar E A Callau wrote:
Thanks all for your comments.
On Apr 21, 2011, at 07:13 , Sven Van Caekenberghe wrote:
I think the problem might be the #listenOn: I use #listenOn:backlogSize: These are using different primitives.
I tested with #listenOn:backlogSize: too, with the same result, error on #waitForAcceptFor: .
Cheers
On 21 Apr 2011, at 15:09, Stéphane Ducasse wrote:
Yes!!!! I forwarded that mail to the network chapter authors. and we will really ask for feedback
This is actually a better variant (it does away with the wait by using the semaphore twice): | serverSocket dataSent dataRead clientStream semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientSocket serverStream | semaphore signal. clientSocket := serverSocket waitForAcceptFor: 10. serverStream := SocketStream on: clientSocket. dataRead := serverStream upToEnd. serverStream close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. semaphore wait. dataSent := 'Hello there!'. clientStream := SocketStream openConnectionToHostNamed: 'localhost' port: 9191. clientStream nextPutAll: dataSent. clientStream close. semaphore wait. self assert: dataSent = dataRead. dataRead | serverSocket clientSocket dataSent dataRead semaphore | semaphore := Semaphore new. serverSocket := Socket newTCP listenOn: 9191 backlogSize: 5. [ [ | clientConnectionSocket | semaphore signal. clientConnectionSocket := serverSocket waitForAcceptFor: 10. dataRead := clientConnectionSocket receiveData. clientConnectionSocket close. semaphore signal ] ensure: [ serverSocket close ] ] forkAt: Processor userBackgroundPriority. semaphore wait. dataSent := 'Hello there!'. clientSocket := Socket newTCP connectToHostNamed: 'localhost' port: 9191. clientSocket sendData: dataSent. clientSocket close. semaphore wait. self assert: dataSent = dataRead. dataRead
participants (4)
-
Oscar E A Callau -
Stephan Eggermont -
Stéphane Ducasse -
Sven Van Caekenberghe