What happens when we create the TCP connection and we wait while(1) i.e. infinite loop, Does it get terminated automatically? or It will last forever if my connection is very good

1 Answer 1


Considering you are not sending any traffic, connection quality has no impact here, because TCP connection on your end-host will not terminate even if you cut the cable between the end-hosts, as long as you don't use optional TCP Keepalive.

In real life networks this is not a very practical way of keeping the connection alive. Firewalls and NATs will eventually flush out the state of this connection in their database, causing the data you might want to transmit at a later time to be dropped, triggering the re-transmission mechanisms in your end-host TCP stack that will eventually lead to session termination.

  • Hello, answer is convincing but they haven't mentioned the amount of time it retries when keepalive didn't get reply Jun 4, 2016 at 13:59
  • 1
    If you use TCP keepalive, there are three values that are of your interest: - time, - interval, - probes. Keepalive process waits for time seconds for socket activity before sending the first keepalive probe, and then resend it every interval seconds. If no ACK response is received for probes consecutive times, the connection is marked as broken. These three values are different by default in different implementations and can also be reconfigured. In linux they are set to 7200, 75 and 9.. Jun 5, 2016 at 10:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.