1
0
mirror of https://github.com/actix/examples synced 2025-02-17 07:23:29 +01:00

Fix pinging so client doesn't get dropped automatically after 10 seconds (#52)

This commit is contained in:
Daniel Kavanagh 2018-09-30 14:09:00 -06:00 committed by Douman
parent d8412fb9bb
commit 62a0101c07
3 changed files with 9 additions and 3 deletions

View File

@ -113,6 +113,9 @@ impl StreamHandler<ws::Message, ws::ProtocolError> 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<ws::Message, ws::ProtocolError> for WsChatSession {
ws::Message::Close(_) => {
ctx.stop();
},
_ => (),
}
}
}

View File

@ -119,6 +119,9 @@ impl StreamHandler<ws::Message, ws::ProtocolError> 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<ws::Message, ws::ProtocolError> for WsChatSession {
ws::Message::Close(_) => {
ctx.stop();
},
_ => (),
}
}
}

View File

@ -52,12 +52,14 @@ impl StreamHandler<ws::Message, ws::ProtocolError> 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();
}
_ => (),
}
}
}