From 1349fdfc73b83a215a8f906d40d5aee008410433 Mon Sep 17 00:00:00 2001 From: deathcap Date: Sat, 23 Jan 2016 18:06:51 -0800 Subject: [PATCH] Update examples to log when connection is lost Normally, the client will send a kick packet if the client is disconnected from the server, but if the connection is lost due to network or lower-level protocol issues, the 'end' event will be emitted. Log this event in the examples so it is clear why the scripts exit. --- examples/client_echo/client_echo.js | 3 +++ examples/client_forge/client_forge.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/examples/client_echo/client_echo.js b/examples/client_echo/client_echo.js index 1f64b4a..3407073 100644 --- a/examples/client_echo/client_echo.js +++ b/examples/client_echo/client_echo.js @@ -18,6 +18,9 @@ client.on('connect', function() { client.on('disconnect', function(packet) { console.log('disconnected: '+ packet.reason); }); +client.on('end', function(err) { + console.log('Connection lost'); +}); client.on('chat', function(packet) { var jsonMsg = JSON.parse(packet.message); if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') { diff --git a/examples/client_forge/client_forge.js b/examples/client_forge/client_forge.js index b8cb159..e4d9e0b 100644 --- a/examples/client_forge/client_forge.js +++ b/examples/client_forge/client_forge.js @@ -20,6 +20,9 @@ client.on('connect', function() { client.on('disconnect', function(packet) { console.log('disconnected: '+ packet.reason); }); +client.on('end', function(err) { + console.log('Connection lost'); +}); client.on('chat', function(packet) { var jsonMsg = JSON.parse(packet.message); if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {