socket-module: different behaviour on windows / unix when a timeout is set

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Jul 11 03:41:22 EDT 2008


En Wed, 09 Jul 2008 15:02:56 -0300, Mirko Vogt <lists at nanl.de> escribi�:

> it seems that the socket-module behaves differently on unix / windows  
> when a timeout is set.
[...]
> Now I will change the code slightly - to be precise I set a timeout on  
> the socket:
>
>
> # test.py
>
> import socket
> sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
> sock.settimeout(3.0) #  <-----
> print 'trying to connect...'
> sock.connect(('127.0.0.1',9999))
> print 'connected!'
>
>
> # executed on linux
>
> $ python test.py
> trying to connect...
> Traceback (most recent call last):
>   File "test.py", line 5, in <module>
>     sock.connect(('127.0.0.1',9999))
>   File "<string>", line 1, in connect
> socket.error: (111, 'Connection refused')
> $
>
>
> # executed on windows
>
>> C:\Python25\python.exe test.py
> trying to connect...
> connected!

Which Python version? Which Windows version? I've tried 2.3.4, 2.4.4,  
2.5.1 and 3.0a4, all on WinXP SP2, and in all cases I got an exception  
(details differ between versions). In no case I could make the connection  
succeed when nobody was listening at port 9999, as expected.

-- 
Gabriel Genellina




More information about the Python-list mailing list