From 62a0101c070deba5e1bbbce35bf146fc5b113808 Mon Sep 17 00:00:00 2001 From: Daniel Kavanagh Date: Sun, 30 Sep 2018 14:09:00 -0600 Subject: [PATCH] Fix pinging so client doesn't get dropped automatically after 10 seconds (#52) --- websocket-chat/src/main.rs | 4 +++- websocket-tcp-chat/src/main.rs | 4 +++- websocket/src/main.rs | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/websocket-chat/src/main.rs b/websocket-chat/src/main.rs index a6917a0e..477b8e40 100644 --- a/websocket-chat/src/main.rs +++ b/websocket-chat/src/main.rs @@ -113,6 +113,9 @@ impl StreamHandler for WsChatSession { self.hb = Instant::now(); ctx.pong(&msg); } + ws::Message::Pong(_) => { + self.hb = Instant::now(); + } ws::Message::Text(text) => { let m = text.trim(); // we check for /sss type of messages @@ -183,7 +186,6 @@ impl StreamHandler for WsChatSession { ws::Message::Close(_) => { ctx.stop(); }, - _ => (), } } } diff --git a/websocket-tcp-chat/src/main.rs b/websocket-tcp-chat/src/main.rs index eefd1506..099ba8d4 100644 --- a/websocket-tcp-chat/src/main.rs +++ b/websocket-tcp-chat/src/main.rs @@ -119,6 +119,9 @@ impl StreamHandler for WsChatSession { self.hb = Instant::now(); ctx.pong(&msg); } + ws::Message::Pong(_) => { + self.hb = Instant::now(); + } ws::Message::Text(text) => { let m = text.trim(); // we check for /sss type of messages @@ -189,7 +192,6 @@ impl StreamHandler for WsChatSession { ws::Message::Close(_) => { ctx.stop(); }, - _ => (), } } } diff --git a/websocket/src/main.rs b/websocket/src/main.rs index da8399f0..84aa4646 100644 --- a/websocket/src/main.rs +++ b/websocket/src/main.rs @@ -52,12 +52,14 @@ impl StreamHandler for MyWebSocket { self.hb = Instant::now(); ctx.pong(&msg); } + ws::Message::Pong(_) => { + self.hb = Instant::now(); + } ws::Message::Text(text) => ctx.text(text), ws::Message::Binary(bin) => ctx.binary(bin), ws::Message::Close(_) => { ctx.stop(); } - _ => (), } } }