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

Function echo_ws

websockets/echo-actorless/src/main.rs:34–41  ·  view source on GitHub ↗

Handshake and start basic WebSocket handler. This example is just for simple demonstration. In reality, you likely want to include some handling of heartbeats for connection health tracking to free up server resources when connections die or network issues arise.

(req: HttpRequest, stream: web::Payload)

Source from the content-addressed store, hash-verified

32/// some handling of heartbeats for connection health tracking to free up server resources when
33/// connections die or network issues arise.
34async fn echo_ws(req: HttpRequest, stream: web::Payload) -> Result<HttpResponse, Error> {
35 let (res, session, msg_stream) = actix_ws::handle(&req, stream)?;
36
37 // spawn websocket handler (and don't await it) so that the response is returned immediately
38 rt::spawn(handler::echo_ws(session, msg_stream));
39
40 Ok(res)
41}
42
43/// Send message to clients connected to broadcast WebSocket.
44async fn send_to_broadcast_ws(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected