3

In the documentation of the socket module it is written that:

Sockets are always created in blocking mode. In blocking mode, operations block until complete or the system returns an error (such as connection timed out).

Also, this SO answer says:

By default, if no explicit timeout is set for the socket, it will block while doing so and eventually timeout, raising exception socket.error: [Errno 110] Connection timed out

My question is, in what situation a blocking socket (or is it the OS?) will raise a timeout? Can I have some control over this timeout, or is the only thing I can do is to catch the exception?

EDIT Am I mixing the socket timeout with connection timeout? What is the difference?

Community
  • 1
  • 1
Itamar Katz
  • 9,544
  • 5
  • 42
  • 74

1 Answers1

1

If you don't set them, your Operating System will control the connect timeout. TCP/IP in blocking mode has three different timeouts:

  • Connect.
  • Read.
  • Write.

To access connect timeouts and to understand how TCP/IP connect work, you should check out the tcp_syn_retries system configuration value on Linux.

EDIT: connect phrase contains some SYNC "handshake" packets while read/write phrase is a "normal" packet. That is the difference.

charlie
  • 389
  • 3
  • 16
hainguyen
  • 101
  • 1
  • 4