[Python-checkins] r58100 - python/trunk/Lib/test/test_ssl.py

Eric Smith eric+python-dev at trueblade.com
Wed Sep 12 03:08:29 CEST 2007


Guido van Rossum wrote:
> On 9/11/07, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> bill.janssen wrote:
>>> Author: bill.janssen
>>> Date: Tue Sep 11 01:41:24 2007
>>> New Revision: 58100
>>>
>>> Modified:
>>>    python/trunk/Lib/test/test_ssl.py
>>> Log:
>>> A better way of finding an open port to test with.
>> Binding to port 0 tells the OS to find an open port for you (someone
>> pointed out this trick a while back for some of the other standard
>> library server tests)
> 
> Is that universal for all platforms including Windows?

I believe so, yes.

For Windows, see http://msdn2.microsoft.com/en-us/library/ms737550.aspx

"The bind function is used on an unconnected socket before subsequent 
calls to the connect or listen functions."

"For TCP/IP, if the port is specified as zero, the service provider 
assigns a unique port to the application with a value between 1024 and 
5000. The application can use getsockname after calling bind to learn 
the address and the port that has been assigned to it."

For Berkeley sockets, Stevens' "Unix Network Programming" says 
essentially the same thing in section 6.8, Reserved Ports.

I've never seen a system using sockets that doesn't behave this way, 
although of course anything is possible.

Eric.


More information about the Python-checkins mailing list