Are TCP sockets persistent?
I am experiencing a socket break between a C ++ client running on a Raspberry Pi3 and a ReactPHP server running on a Centos7 with Php7. See the following:
- The client creates a socket connection to the server using TLS over TCP on port 1337.
- The client can write data to the server.
- The server can write data to the client.
- Tshark runs on both machines with a filter for port 1337 only and sees this initial message.
- No communication occurs for the next hour, and Tshark acknowledges no communication on both machines.
- Neither the client nor the server received a tight connection and thinks that the connection is still open.
- The server then tries to write some more data to the client, Tshark sees the transfer on the server wire, but Tshark does not see the transfer on the clients wire, and obviously the client is not responding.
- If the client daemon exits, the server detects that the connection has been closed.
- If the server daemon is terminated and not by the client daemon, the client does not realize that the connection has been closed.
php.ini shows default_socket_timeout as 60 seconds and changing the value has no effect.
What is causing this and how to prevent it?
thank
+3
source to share
1 answer
Have you tried setting the SO_KEEPALIVE option on your client socket?
Here's some information on how it works and why your connection might only expire on one side. http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/overview.html
using:
char val = 1;
setsockopt(my_socket, SOL_SOCKET, SO_KEEPALIVE, &val, 1);
0
source to share