Hello, I’m developing application which uses websockets for chatting feature.

I was wondering what is best way to store all client handles in server side. Every tutorial (eg. this) just says to store in some form of map. I figured that in large commercial apps list of clients would be rather high and I wondered if storing it on heap is actually valid implementation or if some other solutions like caching dbs like redis are used.

What’s your experience with that?

  • riklaunim@programming.dev
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    1 year ago

    Why do you want to store them? I used socket.io in one app and I used channels to manage who gets what but disconnects/reconnects would happen often so I didn’t use the connection directly, but emitting messages to clients currently subscribed to a given channel.

    Agents log into the dashboard - connect and the server subscribes them to the “agents” channel to which ticket list items messages are emitted. Clicks on a ticket - that’s a ticket_id unique channel to which he gets subscribed. Any disconnect/reconnect would create a new connection, the old one is dropped and the agent is once again subscribed to these channels based on where in the dashboard he is in.

    • towerful@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      Socket.io is abstracting away the client connection details, so is doing the storage itself.

      Socket.io might not be available for the chosen language, socket.io might not be suitable for the project, some people want to develop things themselves.