Jump to content

Do TCP sockets expire?


NotionCommotion

Recommended Posts

A c++ client connects to a Reactphp server using TCP sockets on port 1337.  The client is able to write data to the server and the server is able to write data to the client, and all is good.

 

Tshark is running on both machines with a filter for just port 1337, and sees this initial communication.

 

No communication occurs between the two for the next hour, and Tshark on both machines confirms no communication occurred.  Neither the client or server received a close connection, and think the connection is still open.  The server then attempts to write some more data to the client, Tshark sees the transmission on the server wire, but the Tshark doesn't see the transmission on the clients wire, and obviously the client doesn't respond.  The client daemon is then shutdown, and the server senses that the connection has been closed.

 

php.ini shows default_socket_timeout as being 60 seconds and changing the value does not appear to have any affect.

 

What is causing this and how do I prevent it?

 

Thank you

 

Link to comment
Share on other sites

What are the os's of the client and server?

 

Is there a proxy/firewall in between the client & server?

 

Are you checking for keepalive packets? (ack with an otherwise empty packet).

 

TCP sockets do have variable timeouts that should close them on lack of activity.

Link to comment
Share on other sites

What are the os's of the client and server?

 

Is there a proxy/firewall in between the client & server?

 

Are you checking for keepalive packets? (ack with an otherwise empty packet).

 

TCP sockets do have variable timeouts that should close them on lack of activity.

 

Thanks gizmola,

 

Client is a pi and server is Centos.

 

Yes, there are firewalls protecting both, but I don't think this is the issue.

 

I've briefly looked at http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html.

 

I've since implemented a temp solution of sending a json rpc heartbeat, and it seems to work, will look more into the above referenced link.

Link to comment
Share on other sites

  • 2 weeks later...

NAT firewalls can be a problem because the firewall proxies the connection and performs the NAT of course. The firewall itself can have limited resources and typically, implements a connection queue where it will drop the oldest connections. Some form of keep alive is useful in making sure that an active connection doesn't get killed on one side or the other, due to timeout over a long period.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.