Most socket API's allow for the creation of a server socket on the next available port, often by specifying 0 instead of a port. When the socket is bound, one can retrieve the local port and let the client(s) know. I tried to do that in Pharo today, and these steps seem to work, by accepting an incoming connection gives a primitive failed.
Anyone tried this ?
| socket |
socket := Socket newTCP.
socket listenOn: 0.
[ [
Transcript crShow: 'Port is ', socket localPort printString.
(socket waitForAcceptFor: 60)
ifNotNil: [ :client | | data |
data := client receiveDataTimeout: 30.
Transcript crShow: 'Received ', data asString.
data ifNotNil: [ client sendData: data reverse; close ]
].
] ensure: [ socket close ] ] fork.
I am running the Pharo Cog VM on Mac OS X using Pharo 1.4.
Thx,
Sven
smime.p7s
Description: S/MIME cryptographic signature
