[PEAK] tools.server.url

Wayne Larsen wayne at larsen.st
Tue Oct 19 16:51:48 EDT 2004


On 19-Oct-04, at 2:18 PM, Bob Ippolito wrote:

> On Oct 19, 2004, at 15:50, Phillip J. Eby wrote:
>
>> Also, I'm surprised that using port 0 doesn't work to allocate an 
>> available port.  That almost seems to me like something's broken in 
>> OS/X, but maybe it's a general BSD thing.  (Ty: any thoughts on that? 
>>  Bob?)
>
> It works on OS X 10.3.. I don't know why it doesn't work in his 
> application.
>
> >>> import socket
> >>> sockets = socket.getaddrinfo(None, 0, 0, socket.SOCK_STREAM, 0, 
> socket.AI_PASSIVE)
> >>> sockets
> [(30, 1, 6, '', ('::', 0, 0, 0)), (2, 1, 6, '', ('0.0.0.0', 0))]
> >>> for (af, socktype, proto, canonname, sa) in sockets:
> ...     s = socket.socket(af, socktype, proto)
> ...     s.bind(sa)
> ...     s.listen(5)
> ...     print s.getsockname()
> ...
> ('0.0.0.0', 53591, 0, 0)
> ('0.0.0.0', 53592)
> >>>
>
I tried your example, and it worked fine.  Upon examination, the 
difference seems to be in the socket type  and protocol that are coming 
in.  When I set the socket url to: 'tcp://127.0.0.1:8000', the socket 
type and protocol come in as 1 and 6 respectively.  However, when the 
socket url is 'tcp://127.0.0.1:0', the socket type and protocol are 
coming in as 0 and 0.  The socket type of 0 is what is throwing the 
exception that I was seeing.

Note that localhost also doesn't work for me (where explicitly using 
127.0.0.1 does, but that may be an issue in my config?

Hope that helps,
Wayne




More information about the PEAK mailing list