eminfedar/async-sockets-cpp

TCP socket closed after 5 seconds

Closed this issue · 3 comments

Hi.
I got weird behavior when using the library, specifically TCP socket.

Every time I open TCP client (TCPSocket) and connects to a TCP server, it (the client) closes after 5 seconds without activity, and then the onSocketClosed event is fired.
It happened when I tried to connect to other computer and also when I'm running the examples (tcp-client.cpp and tcp-server.cpp) on localhost (127.0.0.1).
When I place endless while loop with sending data to the server in it (and a small delay) inside the onConnected lambda function - the server prints the text I send and the socket stays open and not being closed automatically.

changing the value of the timeout (using Socket.setTimeout() function) does not affect the behavior.

edit:
I have noticed that this weird timeout is in the length of the timeout that defined in tcpsocket.h,
and using Socket.setTimeout() does not seems to change this value.

I'm using Ubuntu 18.04.
the /proc/sys/net/ipv4/tcp_keepalive_time set to the default - 7200,
the /proc/sys/net/ipv4/tcp_retries1 set to the default - 3,
and the /proc/sys/net/ipv4/tcp_retries2 also set to the default - 15

thanks!

Probably my mistake, I will try to fix it asap.

It is probably fixed. I tried it and reproduced your error. And I have fixed it, you can try and report if something wrong.
c833204

I have removed setTimeout because it creates lots of problem. So I have just added timeout for connection. You can remove that line too. Check the new examples.

It looks like the problem is solved!
thanks!!!