Answer the question
In order to leave comments, you need to log in
How to return socket.io connections after disconnect output on page refresh?
I create a socket connection that breaks after a page refresh. If the server side is restarted, then connections are restored. How can disconnect be handled to return connections.
connection per client
socketio(window.location.hostname+':8000', {
transports: ['polling', 'websocket'],
reconnection: true,
autoConnect: true,
timeout: 50000
})
let app = express();
/*...*/
server = app.listen(8000);
Socket.runConnection(server);
/*...*/
export class Socket {
/*....*/
public runConnection(app){
this.io = socketIo(app,{
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
'sync disconnect on unload': true
});
this.io.adapter(sio_redis(RedisConfig));
this.listen();
}
public listen(){
let self = this;
/*....*/
this.io.on('connection', function(socket:SocketIO.Socket) {
console.log(`connection ${socket.id}`);
socket.on('disconnect', function (reason) {
/*....*/
});
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question