title: Linux TCP Connection timeout
body: <p>I observe the TCP timeout from server to client.
  When TCP Three-way Handshake finished, and then the client does not anything for a long time.
  How many times will timeout TCP sessions?</p>
  <p>I consult the RFC 793 document, 3.8  Interfaces:</p>
  <blockquote>
  <p>The timeout, if present, permits the caller to set up a timeout
  for all data submitted to TCP.   If data is not successfully delivered to the destination within the timeout period, the TCP will abort the connection.<br />
  The present global default is five minutes</p>
  </blockquote>
  <p>The following is the captured packet connection,
  More than 10 minutes have passed and there is no TCP disconnection.</p>
  <p>Am I  misunderstanding somewhere?
  <a href="https://i.stack.imgur.com/Mh8EQ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mh8EQ.jpg" alt="enter image description here" /></a></p>
  <p>OS: Ubuntu 20</p>
  <p>The following is my test code.</p>
  <p>Client Code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  int main(int argc, char *argv[]){
      int socket_desc;
      struct sockaddr_in server;
      
      socket_desc = socket(AF_INET, SOCK_STREAM, 0);
      if(socket_desc == -1){
        printf(&quot;Socket failed\n&quot;);
      }
  
      server.sin_addr.s_addr = inet_addr(&quot;192.168.88.88&quot;);
      server.sin_family = AF_INET;
      server.sin_port = htons(8888);
  
      if(connect(socket_desc, (struct sockaddr *)&amp;server, sizeof(server)) &lt;0){
        printf(&quot;Connect failed\n&quot;);
      } else{
        printf(&quot;Connected\n&quot;);
        while(0); // When connected, do not anything.
  return 0;
  }
  </code></pre>
  <p>Server Code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  int main(int argc, char *argv[]){
      int socket_desc, new_socket, c;
      struct sockaddr_in server;
      
      socket_desc = socket(AF_INET, SOCK_STREAM, 0);
      if(socket_desc == -1){
        printf(&quot;Socket failed\n&quot;);
      }
  
      server.sin_addr.s_addr = INADDR_ANY;
      server.sin_family = AF_INET;
      server.sin_port = htons(8888);
  
      if(bind(socket_desc, (struct sockaddr *)&amp;server, sizeof(server)) &lt;0){
        printf(&quot;bind failed\n&quot;);
      }
  
      listen(socket_desc, 5);
      c = sizeof(struct sockaddr_in);
      new_socket = accept(socket_desc, (struct sockaddr *) &amp;client, (socklen_t *) &amp;c);
      if (new_socket &lt; 0){
        printf(&quot;Accept failed\n&quot;);
      } else{
        printf(&quot;Accept\n&quot;);
        while(1); // When accept , do not anything.
      }
  return 0;
  }
  </code></pre>