I have a net client connection to a socket (using net.createConnection(port,host). this works fine.
However, sometimes there is the possibility of the server dropping the connection, and I would like the net connection to automatically reconnect when the server is back up and running
I can trap the on('end') event to catch the initial disconnect, and try to reconnect.
However,how can I check to see if the client has connected, because I want to retry every n milliseconds on a backoff strategy
Socket disconnects automatically, reconnects, and disconnects again and form a loop. #918.
What is allowHalfOpen? allowHalfOpen {boolean} Indicates whether half-opened TCP connections are allowed. See net. createServer() and the 'end' event for details. Default: false .
socket.connect(path[, connectListener]) Opens the connection for a given socket. If port and host are given, then the socket will be opened as a TCP socket, if host is omitted, localhost will be assumed. If a path is given, the socket will be opened as a Unix socket to that path.
// make a connection with the user from server side io. on('connection', (socket)=>{ console. log('New user connected'); }); Similarly, from the client-side, we need to add a script file and then make a connection to a server through which users send data to a server.
In your end
handler, set a timeout that will retry the connection, and set a one time connect
handler that will cancel the timeout.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With