small_ticket
small_ticket

Reputation: 2030

Connection between client and server doesn't end

I have a Java server. Clients connect to server via TCP. Here is the case for my problem: 1- 2 clients connect to server(client a & client b) 2- clients communicate with server 3- "client a" disconnects from internet 4- The socket connection of client a doesn't disconnects 5- when "client a" connects to the internet again, "client a" can send messages to the server without connecting to the server.

I expect the connection between server and "client a" ends when "client a" disconnects from internet.

Do you have any opinions about this?

Upvotes: 0

Views: 408

Answers (2)

David Schwartz
David Schwartz

Reputation: 182865

When a machine disconnects from the Internet, it can't send any data over the Internet. That includes sending the packets necessary to close or abort a connection. So there is no way the client can close the connection if it gets disconnected. If this needs to be done, the server has to do it. If you need this ability, the application protocol has to provide it.

Upvotes: 0

corsiKa
corsiKa

Reputation: 82589

Well having opinions and having solutions are two different things :-)

I would recommend adding a keepalive time out to your connection on the server side. Send a keep alive every (few seconds? few minutes?) and if there isn't a keepalive response, kill the connection on the server side.

Upvotes: 2

Related Questions