Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io detect disconnect reason

I am using socket.io,can I detect the disconnect reason from disconnect event ? I can see in log files like this

info: transport end (booted) info: transport end (close timeout) info: transport end (error)

I want to get the reason (booted,close timeout,error) I will use like this:

socket.on('disconnect', function(){
   console.log('User 1 disconnected because '+reason);
});

Can I get the reason ?

EDIT:I found the solution

socket.on('disconnect', function(reason){
   console.log('User 1 disconnected because '+reason);
});
like image 217
user2997295 Avatar asked Jan 16 '14 21:01

user2997295


People also ask

Does Socket.IO reconnect after disconnect?

Socket disconnects automatically, reconnects, and disconnects again and form a loop. #918.

Why Socket is not connected?

The error message “ERR_SOCKET_NOT_CONNECTED” is instantly solved in the majority of the cases when we flush the sockets on your browser. This will break the connection between any active pages on your browser and you might have to reinitialize everything.


1 Answers

socket.on('disconnect', function(reason){
   console.log('User 1 disconnected because '+reason);
});

This is the solution.

Possible reasons for disconnect are now documented.

like image 94
user2997295 Avatar answered Oct 02 '22 01:10

user2997295