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)
| 32 | /// some handling of heartbeats for connection health tracking to free up server resources when |
| 33 | /// connections die or network issues arise. |
| 34 | async 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. |
| 44 | async fn send_to_broadcast_ws( |
nothing calls this directly
no outgoing calls
no test coverage detected