GithubHelp home page GithubHelp logo

Comments (3)

maarteNNNN avatar maarteNNNN commented on June 4, 2024

You could do that, but for that you would have to track clients yourself. SocketCluster itself provides socket.id's but these will change on reconnects. I tested this the changing of the ids via the a client:

const socket = sccClient.create({
  hostname: 'localhost',
  port: 8000,
  autoConnect: false,
});

(async () => {
  socket.connect();

  for await (const event of socket.listener('connect')) {
    console.log('connected', socket.id);

    socket.disconnect();

    setTimeout(() => {
      console.log('reconnecting');
      socket.reconnect();
    }, 1000);
  }

  for await (const event of socket.listener('disconnect')) {
    console.log('disconnected', socket.id);
  }
})()

outputs:

connected ba2gYsb9F-gzcQ-EAAAH
reconnecting
connected aYns1ySMFa41s-MFAAAI
reconnecting
connected EtUcSTujH4pNWZKKAAAJ

What could work is that you set a uuid on the client, send it to the server and if it disconnects store the payload somewhere and send it again once the same uuid connects again. Although this probably require some convoluted code to achieve that. I'm unclear if there is something built in to SC @jondubois for this?

from socketcluster.

UsmanShafaqat007 avatar UsmanShafaqat007 commented on June 4, 2024

you are talking about the connection and disconnection update
i am talking about the update that clients missed during their socket disconnection.
e.g the socket is down due to the network and there are some messages for the client during that time how can we send that messages again when the client socket is connected.

from socketcluster.

maarteNNNN avatar maarteNNNN commented on June 4, 2024

Let me rephrase, you can't rely on socket.id. You will have to setup ids of your own on your clients, on connection you will pass them on to the server and then you can track what's their state (connected or disconnected). I don't think this will be easy to implement.

I suggest that you instead store the messages on the server and use .invoke('latest') on the client and setup a route .procedure('latest') that provides the latest updates.

Make sense?

from socketcluster.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.