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


Reply via email to