[Pharo-project] Socket listenOn: 0 & accept

Sven Van Caekenberghe sven at beta9.be
Thu Mar 15 14:07:45 EDT 2012


On 15 Mar 2012, at 18:58, Eliot Miranda wrote:

> In trunk (and in my Cog vm source) they are in the directories
> 
> http://squeakvm.org/svn/squeak/trunk/platforms/{Cross,Mac OS,unix,win32}/plugins/SocketPlugin
> 
> i.e. in all VMs locate the relevant platforms hierarchy and look in platforms/{Cross,Mac OS,unix,win32}/plugins/SocketPlugin.

Thank you, Eliot. 

Sven

> On 09 Mar 2012, at 16:44, Sven Van Caekenberghe wrote:
> 
> > 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
> >
> 
> 
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4334 bytes
Desc: not available
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20120315/7ce23e13/attachment.p7s>


More information about the Pharo-dev mailing list