Pb when connecting to unopened ports and using socket timeout

popov google at evpopov.com
Tue Sep 9 12:35:00 EDT 2003


Hello,

When using the timeout option with a socket object (python 2.3), I
don't have the same behaviour under Windows than under Linux / Mac.

Specifically, if trying to connect to an unopened port of the
localhost, I get a timeout exception on Windows (tested under W2K
Server), whereas I get a "111 - Connection Refused" exception on Linux
and "22 - Invalid Argument" on Mac (OS X).

Even if the error message under Mac is not really appropriate, I think
that the behaviour under Linux and Mac is the right one, in that it
sends (quickly) an error message and not timeouting.

Note that when using blocking socket the behaviour is ok under all
platforms: they each return back quickly a "Connection refused" error
message (err codes are different depending on the platform (61=Mac,
111=Linux, 10061=Windows)).

What do you think ?

I heard that the timeout option was implemented based on Timothy
O'Malley timeoutsocket.py. Then, maybe the pb can come from the usage
of select in the connection function: select is not asked to get back
exceptions in the returned triple, whereas I think some errors can be
returned back through this mean under Windows (according to Tip 25 of
Jon C. Snader book's "Effective TCP/IP Programming"). So, by not
checking the returned exceptions, we would miss the "connection
refused" error and get instead the timeout error...




More information about the Python-list mailing list