Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-16 Thread drush66

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.
 
 socket listenOn: 0.
 

I would say that: 

socket listen.

would be nicer interface than giving special meaning to number 0 in this
context.

Davorin Rusevljan




-
http://www.cloud208.com/
--
View this message in context: 
http://forum.world.st/Socket-listenOn-0-accept-tp4459813p4477991.html
Sent from the Pharo Smalltalk mailing list archive at Nabble.com.



Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-15 Thread 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
Description: S/MIME cryptographic signature


Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-15 Thread Eliot Miranda
On Tue, Mar 13, 2012 at 4:43 AM, Sven Van Caekenberghe s...@beta9.bewrote:

 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

http://squeakvm.org/svn/squeak/trunk/platforms/{Cross,MacOS,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.


 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
 




-- 
best,
Eliot


Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-15 Thread Sven Van Caekenberghe

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
Description: S/MIME cryptographic signature


Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-09 Thread Philippe Marschall

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





Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-09 Thread 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.

[…]

smime.p7s
Description: S/MIME cryptographic signature


Re: [Pharo-project] Socket listenOn: 0 accept

2012-03-09 Thread Norbert Hartl

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.
 
Well, I think it is sort of a definition thing. From the protocol perspective 0 
is a valid port number in the priviledged segment (0-1023). But reservation of 
services is done via IANA and there port 0 is reserved for UDP and TCP. For 
your own services you usually wouldn't choose a reserved port numbe like 
80,22,etc. That makes 0 kind of free for intermediate use :) 

Norbert