MCPcopy Create free account
hub / github.com/actix/examples / handle_ws_msg

Method handle_ws_msg

websockets/echo/src/server.rs:43–76  ·  view source on GitHub ↗
(
        &self,
        msg: AggregatedMessage,
        state: &mut (Instant, actix_ws::Session),
        myself: ActorRef<WsMessage>,
    )

Source from the content-addressed store, hash-verified

41 }
42
43 async fn handle_ws_msg(
44 &self,
45 msg: AggregatedMessage,
46 state: &mut (Instant, actix_ws::Session),
47 myself: ActorRef<WsMessage>,
48 ) -> Result<(), ActorProcessingErr> {
49 println!("WS: {msg:?}");
50
51 match msg {
52 AggregatedMessage::Ping(msg) => {
53 state.0 = Instant::now();
54 state.1.pong(&msg).await?;
55 }
56
57 AggregatedMessage::Pong(_) => {
58 state.0 = Instant::now();
59 }
60
61 AggregatedMessage::Text(text) => {
62 state.1.text(text).await?;
63 }
64
65 AggregatedMessage::Binary(bin) => {
66 state.1.binary(bin).await?;
67 }
68
69 AggregatedMessage::Close(reason) => {
70 let _ = state.1.clone().close(reason).await;
71 myself.stop(None);
72 }
73 };
74
75 Ok(())
76 }
77}
78
79impl ractor::Actor for MyWebSocket {

Callers 1

handleMethod · 0.80

Calls 1

stopMethod · 0.80

Tested by

no test coverage detected