2

I'm establishing a TCP client socket connection to an XMPP server and need a reliable way to detect interruptions in the connection (e.g. server crashes, restarts etc). I have listeners attached to the end, error and close events, but they do not fire reliably when I cut my internet connection during an active connection. How can my client detect when the connection has been broken? I would prefer not to resort to pinging/timeouts.

1 Answer 1

4

I'm in no way an expert on TCP or socket programming, but I'm pretty sure that there exists no "reliable way to detect interruptions in the connection". See e.g. this Unix.com thread.

In node, your options seem to be socket.setTimeout/socket.on('timeout', callback) and/or socket.setKeepAlive.

Edit: Here is a guide on TCP keepalive.

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

1 Comment

but do you see, that socket.setTimeout can be used with keepalive packets?

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.