[Pharo-project] Networking problems on Pharo 1.2.1

Stéphane Ducasse stephane.ducasse at inria.fr
Thu Apr 21 15:09:01 CEST 2011


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
>>> 
>>> 
>> 
> 
> 




More information about the Pharo-project mailing list