Click here to Skip to main content
15,917,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to fetch query string parameters while creating websocket connection. I have used traversed a lot to get the solution, got some answer, but didn't work out for me.

Below is the code i am using...

JavaScript
var url = require('url');
var WebSocketServer = require('websocket').server;
var http = require('http');

var server = http.createServer(function (request, response) { 
    // console.log((new Date()) + ' Received request for ' + url.parse(req.url).pathname);
});


server.listen(1337, function() {
    console.log((new Date()) + ' Server is listening on port 1337');
});


wsServer = new WebSocketServer({
    httpServer: server,
    autoAcceptConnections: false
});

wsServer.on('request', function(r){

    	// Code here to run on connection
	var connection = r.accept(null,r.origin);
	
	// console.log( ' Requested URL : ' + urlAddress.parse(r.url,true) );

	connection.on('close', function(reasonCode, description) {
    		delete clients[id];
    		console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
	});
});

wsServer.on('connect',function(request,socket,head){
		//console.log(request.url);
});


Please help me ...
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900