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?
I consult the RFC 793 document, 3.8 Interfaces:
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.
The present global default is five minutes
The following is the captured packet connection, More than 10 minutes have passed and there is no TCP disconnection.
Am I misunderstanding somewhere?
OS: Ubuntu 20
The following is my test code.
Client Code:
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
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("Socket failed\n");
}
server.sin_addr.s_addr = inet_addr("192.168.88.88");
server.sin_family = AF_INET;
server.sin_port = htons(8888);
if(connect(socket_desc, (struct sockaddr *)&server, sizeof(server)) <0){
printf("Connect failed\n");
} else{
printf("Connected\n");
while(0); // When connected, do not anything.
return 0;
}
Server Code:
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
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("Socket failed\n");
}
server.sin_addr.s_addr = INADDR_ANY;
server.sin_family = AF_INET;
server.sin_port = htons(8888);
if(bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) <0){
printf("bind failed\n");
}
listen(socket_desc, 5);
c = sizeof(struct sockaddr_in);
new_socket = accept(socket_desc, (struct sockaddr *) &client, (socklen_t *) &c);
if (new_socket < 0){
printf("Accept failed\n");
} else{
printf("Accept\n");
while(1); // When accept , do not anything.
}
return 0;
}