[Pharo-project] Networking problems on Pharo 1.2.1

Sven Van Caekenberghe sven at beta9.be
Fri Apr 22 11:23:54 CEST 2011


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




More information about the Pharo-project mailing list