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 (5K) Download Attachment |
On 03/09/2012 04:44 PM, 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. Stupid n00b question, isn't 0 a valid port number? Cheers Philippe |
On 09 Mar 2012, at 16:56, Philippe Marschall wrote: > On 03/09/2012 04:44 PM, 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. > > Stupid n00b question, isn't 0 a valid port number? I don't think so, in Java: http://docs.oracle.com/javase/1.4.2/docs/api/java/net/ServerSocket.html#ServerSocket() ServerSocket public ServerSocket (int port) throws IOException Creates a server socket, bound to the specified port. A port of 0 creates a socket on any free port. […] smime.p7s (5K) Download Attachment |
Am 09.03.2012 um 18:44 schrieb Sven Van Caekenberghe: > > On 09 Mar 2012, at 16:56, Philippe Marschall wrote: > >> On 03/09/2012 04:44 PM, 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. >> >> Stupid n00b question, isn't 0 a valid port number? > > I don't think so, in Java: > > http://docs.oracle.com/javase/1.4.2/docs/api/java/net/ServerSocket.html#ServerSocket() > > ServerSocket > > public ServerSocket (int port) throws IOException > > Creates a server socket, bound to the specified port. A port of 0 creates a socket on any free port. > Norbert |
In reply to this post by Sven Van Caekenberghe
Can anyone please help me and show me where I should look if I wanted to see the exact C code implementing the socket primitives (for the Pharo built Cog VMs) ?
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 > smime.p7s (5K) Download Attachment |
On Tue, Mar 13, 2012 at 4:43 AM, Sven Van Caekenberghe <[hidden email]> wrote: Can anyone please help me and show me where I should look if I wanted to see the exact C code implementing the socket primitives (for the Pharo built Cog VMs) ? In trunk (and in my Cog vm source) they are in the directories
<a href="http://squeakvm.org/svn/squeak/trunk/platforms/{Cross,Mac">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.
best, Eliot |
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 > > > > > > > smime.p7s (5K) Download Attachment |
In reply to this post by Sven Van Caekenberghe
I would say that: socket listen. would be nicer interface than giving special meaning to number 0 in this context. Davorin Rusevljan |
Free forum by Nabble | Edit this page |