Code Monkey home page Code Monkey logo

Comments (4)

theturtle32 avatar theturtle32 commented on July 21, 2024

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.

gertcuykens avatar gertcuykens commented on July 21, 2024

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.')})
})

  1. Connection has already remoteAddress available, so resource would make it consistent?
  2. I would like to use the connection resource as a session id to figure out which connection is from which user?

from websocket-node.

theturtle32 avatar theturtle32 commented on July 21, 2024

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.

theturtle32 avatar theturtle32 commented on July 21, 2024

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)

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.