0

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

1 Answer 1

1

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. i.e. the client and/or server periodically sends (e.g. 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.

Sign up to request clarification or add additional context in comments.

1 Comment

I just created a keepalive packet that is send every minute. Or does it have to be more often? When It's fixed I will mark the answer as accepted. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.