sitegui / nodejs-websocket

A node.js module for websocket server and client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Are query parameters supported?

rcoenen opened this issue · comments

The WebSocket specification states that this is a valid websocket URI:
ws://myserver.com/path?param=1

However I am unsure if nodejs-websocket supports access to the URI parameters.

Can anyone tell me if this is supported (and if yes, how to use it)?

Thanks

The Connection is passed as parameter to the "connection" listener, so you could do:

var ws = require("nodejs-websocket");

var server = ws.createServer(function (conn) {
	console.log(conn.path); // /path?param=1
	
        // ...
}).listen(8001)

But as far as I looked at the source, you would have to process the string yourself, there are no utility methods in the library itself.

You could use the querystring module of node's to parse the parameters after splitting the path on ?