Pb when connecting to unopened ports and using socket timeout

P

popov

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top