How can I tell the difference between setting and not setting socket.setKeepAlive ()?

set socket.setKeepAlive (true, 1000) on the client, while the server setting socket.setTimeout (2000) the server still triggers the timeout event? Isn"t the function of setKeepAlive to send packets to the server regularly when there is no data transmission?

May.09,2021

socket.setKeepAlive () means to send an empty packet confirmation if there is no connection at a specified time.

socket.setTimeout () similarly, it will trigger if there is no connection within the specified time, but will not send an empty packet confirmation. Of course, you can send an confirmation packet through the socket in the callback function, which is similar to setKeepAlive. In addition, the timeout event will be triggered.

this is an article I have read before. It is written in great detail. You can take a look at it. Click here

Menu