Code Monkey home page Code Monkey logo

Comments (5)

theturtle32 avatar theturtle32 commented on July 21, 2024 1

WebSocket-Node doesn't have connection IDs, nor does it need them for anything. If you wish to use a connection ID, you may assign one when you accept each connection:

var connectionIdCounter = 0;
server.on('connection', function(connection) {
   connection.id = connectionIdCounter++;
});

from websocket-node.

joejoe avatar joejoe commented on July 21, 2024

Thanks. I might be missing something though. Currently I am using the other server I mentioned and am storing data to a redis server using the key of connectionid. Then when they disconnect, Or we kill node, I can clear that info based on connectionid.

Will your solution work for this? Meaning, once I set connectionid via your method, is it the same?

Thanks.
Joe

from websocket-node.

theturtle32 avatar theturtle32 commented on July 21, 2024

With WebSocket-Node, you are responsible for your own mechanism of assigning connection IDs, since the library itself has no use for them. If you need that feature you will need to figure out what implementation will work for you.

The example I provided just uses simple incrementing integers for the ID. That identifier will be unique for that connection on that server, but if you have multiple servers all communicating together using Redis PubSub or similar, you will want to use an ID that is guaranteed to be more unique.

In that case, I would look into using GUIDs instead, as they're guaranteed to be globally unique.

from websocket-node.

joejoe avatar joejoe commented on July 21, 2024

Got it. Thanks. I'll give it a shot. Thanks for your help.

Joe

from websocket-node.

theturtle32 avatar theturtle32 commented on July 21, 2024

No problem, good luck!

from websocket-node.

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.