Re: socket-module: different behaviour on windows / unix whena timeout is set

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mirko Vogt

    Re: socket-module: different behaviour on windows / unix whena timeout is set

    Gabriel Genellina wrote:
    En Wed, 09 Jul 2008 15:02:56 -0300, Mirko Vogt <lists@nanl.dee scribi�:
    >
    >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.so cket(socket.AF_ INET,socket.SOC K_STREAM)
    >sock.settimeou t(3.0) # <-----
    >print 'trying to connect...'
    >sock.connect(( '127.0.0.1',999 9))
    >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\p ython.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.
    >
    Hey, this is strange.

    Linux:
    $ python --version
    Python 2.5.2
    $

    Windows:
    C:\Python25>pyt hon.exe --version
    Python 2.5.2
    C:\Python25>

    Mirko
Working...