Expand WebSocket example to match on Message (#723)

This commit is contained in:
YuKun Liu 2022-01-25 23:31:33 +08:00 committed by GitHub
parent 32c9ab3c56
commit c0473f2b6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -75,7 +75,24 @@ async fn ws_handler(
async fn handle_socket(mut socket: WebSocket) {
if let Some(msg) = socket.recv().await {
if let Ok(msg) = msg {
println!("Client says: {:?}", msg);
match msg {
Message::Text(t) => {
println!("client send str: {:?}", t);
}
Message::Binary(_) => {
println!("client send binary data");
}
Message::Ping(_) => {
println!("socket ping");
}
Message::Pong(_) => {
println!("socket pong");
}
Message::Close(_) => {
println!("client disconnected");
return;
}
}
} else {
println!("client disconnected");
return;