Comments (5)
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.
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.
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.
Got it. Thanks. I'll give it a shot. Thanks for your help.
Joe
from websocket-node.
No problem, good luck!
from websocket-node.
Related Issues (20)
- The NPM package is not a place for politics HOT 1
- The NPM package is not a place for politics HOT 2
- Get URL Parameters HOT 1
- Ssl using cloudflare
- Send bytes query
- broadcast
- How to connect to multiple WebSockets? HOT 1
- install of websocket and immediatly disapear
- How Can we get Connection URL from w3cwebsocket to webSocket.Server Connection
- Similar to emit socket.io HOT 1
- send to all connected clients HOT 2
- Getting vulnerable issue [email protected]
- Need more docs on the usage of client
- Unable to connect with auth info in url and special characters HOT 1
- connection.on('message', ...) - where this event is emitted ? HOT 1
- This pkg appears abandoned. I recommend switching to "ws", it's a very similar implementation HOT 4
- Malware dependency
- Update UTF-8 Validation Code
- Request to Upgrade es5-ext Dependency to Resolve Veracode Vulnerability HOT 5
- websocket doesn't work under bun HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocket-node.