#Can't connect web socket with tungstenite

16 messages · Page 1 of 1 (latest)

vague valve
#

Hi @placid sapphire may I ask what feature you enable because I get a similar error

pliant steeple
placid sapphire
#
pub fn connect() -> Self {
        
        let (socket, _) = tungstenite::connect(Request::builder().uri(DISCORD_WS).body(()).unwrap())
            .expect("Couldn't connect to discord gateway");
        let mut gateway = Self {
            socket,
            heartbeat_interval: 0,
        };
        let hello = gateway.receive_packet::<HelloPacket>();
        assert_eq!(hello.op, HELLO_OPCODE);
        gateway.heartbeat_interval = hello.d.unwrap().heartbeat_interval;
        gateway
    }

I'm trying to connect to the discord gateway (WebSocket) with tungstenite
But i'm getting this error

tidal hare
#

never used websockets, the only thing I can tell you is a header is invalid idk

placid stag
#

try to use Url::parse like in their examples instead of Request::builder

placid sapphire
#

@placid stag now i get this error

#

error 400

#

btw discord uses wss instead of ws

#

is that the problem?

#

wss://gateway.discord.gg/?v=10&encoding=json

placid stag
#

I have no idea, sorry

placid sapphire
#

uhm

#

i had to enable a feature

#

bcs i'm using tls

#

tungstenite was talking plain text on a encrypted connection

#

that's why the server was responding with 400