Linux Labs

Networking / Stage 6 of 14

From connection to application response

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 7 · theory · 5 min

Refusal and timeout

A request to a site first sets up a connection, and only then does the program receive the request. A failure at the first stage comes in two kinds.

A refusal comes at once: the server's kernel answers that nobody listens on this address and port. curl prints curl: (7) … Couldn't connect to server.

A timeout is a wait that ended without an answer. Either there is no host with that address, or a filter silently drops the packets to it; filters are the next lesson. curl prints curl: (28) … Timeout was reached.

--connect-timeout sets how long to wait for the connection, and --max-time how long to wait for the whole request, both in seconds. Without them curl waits for a connection for up to five minutes, and for an answer after connecting as long as it takes: a program may accept the connection and go silent.

A single connection can be checked without HTTP using nc: nc -zv -w 2 192.0.2.10 8080 prints succeeded or Connection refused.

Check yourself 1 question

ping 192.0.2.10 gets replies, while curl --connect-timeout 3 http://192.0.2.10:8080/ prints Timeout was reached. What is most likely?

  • Without a route ping would fail too, and curl would be refused at once.

  • For an empty port the server's kernel refuses at once with Couldn't connect to server; there is no wait.

  • An error answer is still an answer: curl would print its text or status. Here there was no connection at all.

The host answers ping, so it exists and there is a way to it. Silence on one port is the sign of a filter dropping packets; the next lesson covers it.

Key points

  • A refusal comes at once: nobody listens on the address and port.
  • A timeout means no answer came: the host does not exist, or the packets are dropped.
  • --connect-timeout and --max-time keep a check from hanging.
Ubuntu 24.04
Loading…