mirror of
https://github.com/actix/examples
synced 2024-11-30 17:14:35 +01:00
send the correct exit code when closing the websocket (#335)
Signed-off-by: Bart Willems <bwillems@protonmail.com>
This commit is contained in:
parent
5926035d6c
commit
399fbee1e4
@ -25,6 +25,10 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WebSocket {
|
|||||||
ws::Message::Text(text) => ctx.text(text),
|
ws::Message::Text(text) => ctx.text(text),
|
||||||
ws::Message::Binary(bin) => ctx.binary(bin),
|
ws::Message::Binary(bin) => ctx.binary(bin),
|
||||||
ws::Message::Ping(bytes) => ctx.pong(&bytes),
|
ws::Message::Ping(bytes) => ctx.pong(&bytes),
|
||||||
|
ws::Message::Close(reason) => {
|
||||||
|
ctx.close(reason);
|
||||||
|
ctx.stop();
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,11 +151,10 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WsChatSession {
|
|||||||
}
|
}
|
||||||
self.send_msg(msg);
|
self.send_msg(msg);
|
||||||
}
|
}
|
||||||
|
ws::Message::Close(reason) => {
|
||||||
ws::Message::Close(_) => {
|
ctx.close(reason);
|
||||||
ctx.stop();
|
ctx.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,8 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WsChatSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws::Message::Binary(_) => println!("Unexpected binary"),
|
ws::Message::Binary(_) => println!("Unexpected binary"),
|
||||||
ws::Message::Close(_) => {
|
ws::Message::Close(reason) => {
|
||||||
|
ctx.close(reason);
|
||||||
ctx.stop();
|
ctx.stop();
|
||||||
}
|
}
|
||||||
ws::Message::Continuation(_) => {
|
ws::Message::Continuation(_) => {
|
||||||
|
@ -184,7 +184,8 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WsChatSession {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ws::Message::Binary(_) => println!("Unexpected binary"),
|
ws::Message::Binary(_) => println!("Unexpected binary"),
|
||||||
ws::Message::Close(_) => {
|
ws::Message::Close(reason) => {
|
||||||
|
ctx.close(reason);
|
||||||
ctx.stop();
|
ctx.stop();
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
@ -59,7 +59,8 @@ impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWebSocket {
|
|||||||
}
|
}
|
||||||
Ok(ws::Message::Text(text)) => ctx.text(text),
|
Ok(ws::Message::Text(text)) => ctx.text(text),
|
||||||
Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
|
Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
|
||||||
Ok(ws::Message::Close(_)) => {
|
Ok(ws::Message::Close(reason)) => {
|
||||||
|
ctx.close(reason);
|
||||||
ctx.stop();
|
ctx.stop();
|
||||||
}
|
}
|
||||||
_ => ctx.stop(),
|
_ => ctx.stop(),
|
||||||
|
Loading…
Reference in New Issue
Block a user