Skip to content

Sending an emit right after starting a connection closes the connection. #502

@Sprenkelz

Description

@Sprenkelz

Example

let socket = ClientBuilder::new("wss::server.com")
 .transport_type(rust_socketio::TransportType::Websocket)
 .connect()
 .expect("Failed to connect"");

socket.emit("test", json!({})).expect("Failed to emit test event");

Connects successfully and then sends event successfully but then the connection closes and server doesn't send back a "test" event.

My bandaid fix

let socket = ClientBuilder::new("wss::server.com")
 .transport_type(rust_socketio::TransportType::Websocket)
 .connect()
 .expect("Failed to connect"");

std::thread::sleep(Duration::from::millis(500));

socket.emit("test", json!({})).expect("Failed to emit test event");

Server now sends back a "test" event and things work as expected.

My guess is that ClientBuilder::new returns when a websocket handshake is successful but doesn't wait for the Socket.io handshake. When an emit is immediately sent it interrupts the handshake somehow and the connection gets closed. I'd expect for ClientBuilder::new to wait until a full connection is formed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions