we Define Event handler for Handel "Disconnect" Event.
Just Get Reason we use Following Code.
socket.on('disconnect', function(reason){
console.log('Player Disconnected Due To Reason :'+reason);
});
Start listening for server-sent events from node with the specified eventIdentity.
Will trigger the provided callback function when a matching event is received.
Here 'disconnect' Event Occure when some socket is disconnected.
There Are Following Type of Reason Here we Get.
1) Transport Close
2) Ping Timeout
Transport Close:
When You Close your Application/Game/Webgl, You May Get this Reason.
Ping Timeout :
When you ping time is Expire , You May Get this Reason.
It might be better to set different pingTimeouts on the server and on client.
On server, pingTimeout (+pingInterval) means the idle time the server will keep the socket up. This can be quite long, as the client can sleep while the connection is still kept alive, and continue when it awakens.
On client, the pingTimeout means how long to wait for pong response, 60s is way too long, nothing is going to come if not in a few seconds. Personally I use quite long pingTimeout on server, but on client overwrite it on client handshake event to be a few seconds.
Also the socket.ping() method is more like socket.setPing(), as it pings only after pingInterval, and a quick ping is sent with socket.sendPacket('ping') instead, where the pong can be heard for example by socket.once 'hearbeat'.
Hope this helps somebody.
Thanks.
Just Get Reason we use Following Code.
socket.on('disconnect', function(reason){
console.log('Player Disconnected Due To Reason :'+reason);
});
Start listening for server-sent events from node with the specified eventIdentity.
Will trigger the provided callback function when a matching event is received.
Here 'disconnect' Event Occure when some socket is disconnected.
There Are Following Type of Reason Here we Get.
1) Transport Close
2) Ping Timeout
Transport Close:
When You Close your Application/Game/Webgl, You May Get this Reason.
Ping Timeout :
When you ping time is Expire , You May Get this Reason.
It might be better to set different pingTimeouts on the server and on client.
On server, pingTimeout (+pingInterval) means the idle time the server will keep the socket up. This can be quite long, as the client can sleep while the connection is still kept alive, and continue when it awakens.
On client, the pingTimeout means how long to wait for pong response, 60s is way too long, nothing is going to come if not in a few seconds. Personally I use quite long pingTimeout on server, but on client overwrite it on client handshake event to be a few seconds.
Also the socket.ping() method is more like socket.setPing(), as it pings only after pingInterval, and a quick ping is sent with socket.sendPacket('ping') instead, where the pong can be heard for example by socket.once 'hearbeat'.
Hope this helps somebody.
Thanks.
Thank you for your nice list.
ReplyDeleteNodeJS Online Training in Hyderabad
Best article, very useful and explanation. Your post is extremely incredible. Thank you very much for the new information.
ReplyDeleteNode Js Online Training in Hyderabad
Best Node Js Online Training in Hyderabad
Node Js Training
Node Js Online Training in Ameerpet
very nice blog thanks for the valuable information, i got an idea on How To Get Socket(socket.io) Disconnected Reason - Node js | JavaScript
ReplyDeleteNode JS Online training
Node JS training in Hyderabad