Comments (4)
For the client or the server? Why would you want a URL property on the server's connection object? The WebSocketRequest object has the 'resource' property to provide the path, though I can see utility in also having the 'host' and 'port' components available, perhaps for virtual hosting of some kind. But the utility of that would generally end at the WebSocketRequest object. Once you have the WebSocketConnection object, you already know that information.
I'm not sure why you would want the URL property on the client connection object either, since to make the connection in the first place you would have had to pass it in.
from websocket-node.
var server = require('websocket').server
var ws = new server({httpServer:www,autoAcceptConnections:true})
ws.on('connect',function(connection){
console.log((new Date())+' Connection '+connection.remoteAddress+' accepted.')
connection.on('message',function(message){query(connection,message)})
connection.on('close',function(connection){console.log((new Date()) + ' Peer '+connection.remoteAddress+' disconnected.')})
})
- Connection has already remoteAddress available, so resource would make it consistent?
- I would like to use the connection resource as a session id to figure out which connection is from which user?
from websocket-node.
It's available in the request object. You can keep it around by stuffing it into the connection object when you accept the connection. Ah but I see you're using autoAcceptConnections. I should warn you against that as it accepts connections from any origin so you would be vulnerable to cross-site scripting issues. It's only really meant for throwing together a quick test or proof of concept. I'll try to add an example that exposes the cross-origin mechanism to the README.
Here's a snippet that will give you access to what you want, the 'resource' property. Set 'autoAcceptConnections' to false.
wsServer.on('request', function(request) {
var connection = request.accept('my-great-protocol', request.origin);
connection.resource = request.resource;
}
from websocket-node.
I added the 'host' property to the WebSocketRequest object to help with virtual hosting applications in commit dcb00f2.
NPM version updated to 0.0.8
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.