Skip to content

Client connected but it doesn't receive anything #4

@pagoru

Description

@pagoru

The client is connected fine and can send and receive events, but some times the server doesn't recieve any event and the client is still connected.

The way to reproduce it:
Start and stop the client a few times, until it stops receiveing the pong message.

client:

const socket = io("http://localhost:8080");

socket.on("pong", ({ datetime }) => {
    console.log(`Response time (${(Date.now() - datetime)}ms)`)
});

socket.on("connect", () => {
    console.log(`Connected! ${socket.id}`);
    
    setInterval(() => {
        socket.emit('ping', { datetime: Date.now() });
    }, 1000);
});

socket.connect();

server:

const io = new Server();

io.on("connection", (socket) => {
    console.log(`socket ${socket.id} connected`);
    
    socket.on('ping', (data) => {
        console.log(`[${socket.id}]: ping!`)
        socket.emit('pong', data)
    });
});

await serve(io.handler(), {
    port: 8080,
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions