skip to Main Content

I am developing an online game using socket.io. Node.js in server side and JavaScript on client side. Everything works well but when the client goes offline and comeback online the events are not send to the client. Inside the server is there any sendBuffer for each client ?

To see the exact problem we can use simple chat-example provided by the socket.io team : https://github.com/socketio/chat-example

Here if a client send a message while offline will be send when it reconnects to the server. But if a client is offline while server send a message(forwarded from another client) client will not receive on re-connection.

So how should I solve this issue properly ?

socket.io : v4
OS : Ubuntu 22.04

2

Answers


  1. Chosen as BEST ANSWER

    Sorry! It's well documented here : https://socket.io/docs/v4/delivery-guarantees

    • there is no such buffer on the server, which means that any event that was missed by a disconnected client will not be transmitted to that client upon reconnection

  2. You still need to store the information on the server in case of such situations.

    You can use timeouts
    https://socket.io/docs/v4/emit-cheatsheet/#server-side

    io.timeout(5000).emit("hello", "world", (err, responses) => {
         if (err) {
         //someone did not accept the information, save it somewhere, and send it to the user when reconnecting
         } else {
           console.log(responses); // one response per client
         }
       });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search