On 08 May 2012, at 19:24, Sean P. DeNigris wrote:
> Why doesn't the second listen fail? And is there a way to fail if a port is
> already in use?
>
> socket := Socket newTCP.
> socket listenOn: 8088.
>
> socket2 := Socket newTCP.
> socket2 listenOn: 8088.
>
> (socket isValid and: [ socket2 isValid ])
> ifTrue: [ self error: 'how can I be listening twice on the same port?!'
> ].
>
> socket destroy.
> socket2 destroy
Welcome to the strange world of Sockets, Sean ;-)
I have this test in Zn:
ZnSingleThreadedServer>>isListening
"Return true when I have a valid server socket listening at the correct
port"
^ self serverSocket notNil
and: [ self serverSocket isValid and: [ self serverSocket
localPort = self port ] ]
You can try, maybe it solves your 'problem'.
Sven
--
Sven Van Caekenberghe
http://stfx.eu
Smalltalk is the Red Pill