#Unable to use websockets with Axum

1 messages · Page 1 of 1 (latest)

vast thunder
kind pollen
#

wow that really took a while

vast thunder
#

it didn't

#

I just stumbled across the thread and decided to post the answer

kind pollen
#

oh well ty

vast thunder
#

whenever I try to connect to my websocket server made in Axum I get an error on the server, and in turn, an error on the client.

my code:

use axum::extract::ws::{Message, WebSocket, WebSocketUpgrade};

pub async fn ws_test(ws: WebSocketUpgrade) {
    ws.on_upgrade(inner);
    async fn inner(mut socket: WebSocket) {
        println!("Hi!");
        socket
            .send(Message::Text(String::from("HI!")))
            .await
            .unwrap();

        socket.close().await.unwrap();
    }
}

the error on the server:

Error { inner: Io(Os { code: 10053, kind: ConnectionAborted, message: "An established connection was aborted by the software in your host machine." }) }
vast thunder
#

anyone?

meager solar
#

that might me a result of a panic? considering you only unwrap

kind pollen
#

could be some weird antivirus/firewall stuff

vast thunder
kind pollen
#

i know my antivirus thinks anything i write in rust is a virus so i wouldn't be that surprised, this isn't necessarily a rust issue

#

try copying a minimal example from axum docs and see if that works or if its something thats borked on your machine

vast thunder
#

the example gave a different error

kind pollen
#

what was the examples error?

vast thunder
#

ill check

vast thunder
kind pollen
#

i honestly don't know id suggest you ask in the tokio discord as they're probably better specialised in fixing this sort of stuff https://discord.gg/tokio

vast thunder
#

I didn't know they had their own discord server

#

I'll ask in there