I am making a C# client / Java server chatroom, and everything works fine now, except for one thing: After some time (an hour or so) of not using the application (or using it, I don't know) it gives me a SocketException at the C# client at the socket.EndReceive() function:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Do Java or C# socket connections closes after some time of idling? Or is it just the tcp protocol? What would be the best method to fix it?
Thanks all!
Bas
Do Java or C# socket connections closes after some time of idling?
No.
However, firewalls and especially NAT gateways do, often silently.
What would be the best method to fix it?
Implement a heartbeat procedure. ie the client and/or server periodically sends (eg every 10 or 30 or so seconds) a special message that's just used to keep the connection alive and to faster detect a failed peer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.