Actix/websocket - reactor problem

Hello!
I'm playing with websocket example code
but I have a problem:
there is no reactor running, must be called from the context of a Tokio 1.x runtime

struct MyWebSocket {
    /// Client must send ping at least once per 10 seconds (CLIENT_TIMEOUT),
    /// otherwise we drop connection.
    hb: Instant,
}

impl Actor for MyWebSocket {
    type Context = ws::WebsocketContext<Self>;

    /// Method is called on actor start. We start the heartbeat process here.
    fn started(&mut self, ctx: &mut Self::Context) {
        self.hb(ctx);
    }
}

/// Handler for `ws::Message`
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for MyWebSocket {
    fn handle(
        &mut self,
        msg: Result<ws::Message, ws::ProtocolError>,
        ctx: &mut Self::Context) {
        // process websocket messages
        println!("MyWebSocket WS: {:?}", msg);
        match msg {
            Ok(ws::Message::Ping(msg)) => {
                self.hb = Instant::now();
                ctx.pong(&msg);
            }
            Ok(ws::Message::Pong(_)) => {
                self.hb = Instant::now();
            }
            Ok(ws::Message::Text(text)) => {

                let future = async move {
                    println!("future!");
                    let mut socket_rx = CANSocket::open("vcan0").unwrap();
                    while let Some(Ok(frame)) = socket_rx.next().await
                    {
                         println!("MyWebSocket can frame: {:?}", frame);
                    }
                };

                let fut = actix::fut::wrap_future::<_, Self>(future);
                ctx.spawn(fut);
                //ctx.text(text)
            },
            Ok(ws::Message::Binary(bin)) => ctx.binary(bin),
            Ok(ws::Message::Close(reason)) => {
                ctx.close(reason);
                ctx.stop();
            }
            _ => ctx.stop(),
        }
    }
}

Your version of actix-web is too old for Tokio 1.x.y. See this for more.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.