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

Method handle_hb

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

Source from the content-addressed store, hash-verified

21
22impl MyWebSocket {
23 async fn handle_hb(
24 &self,
25 state: &mut (Instant, actix_ws::Session),
26 myself: &ActorRef<WsMessage>,
27 ) -> Result<(), ActorProcessingErr> {
28 if Instant::now().duration_since(state.0) > CLIENT_TIMEOUT {
29 // heartbeat timed out
30 println!("Websocket Client heartbeat failed, disconnecting!");
31
32 let _ = state.1.clone().close(None).await;
33 myself.stop(None);
34
35 // don't try to send a ping
36 } else {
37 state.1.ping(b"").await?;
38 };
39
40 Ok(())
41 }
42
43 async fn handle_ws_msg(
44 &self,

Callers 1

handleMethod · 0.80

Calls 2

stopMethod · 0.80
pingMethod · 0.80

Tested by

no test coverage detected