I'm trying to build in a reconnection procedure for clients that lose connection. In the client js I can detect when connection is lost and periodically attempt to reconnect to the server. When I reconnect though the server will be using a new socket.
On the client this is my reconnect logic
var socket = io.connect(ip, {
'reconnect': true, //will create a new socket on the server
'reconnection delay': options.retryInterval,
'max reconnection attempts': 10
});
socket.on("disconnect", function() {
this.connected = false;
this.autoretry();
});
//establish the connection - similiar to the reconnect method
socket.emit("connect", this.options);
//....
autoretry: function() {
if(this.connected) {return;};
var next = this.__retry *= this.options.retryScalar;
this.socket.emit("retry", this.connect.options);
return _.delay(this.autoretry, next, this);
}
The problem is each client has it's own tls
connection to an external server and I would like to hold this connection open for a brief period; waiting to see if the client reconnects.
Is there a good way to uniquely identify the client in node or should I create the identifier on the client and pass it to the server?