Hi Ray, 

Whenever I use a websocket, I track the origin of the socket.  In my case, 
I add a query param with some identifying information such as an authkey 
which was dynamically generated on page load and inserted into the client 
via javascript.  When I make the request to open the socket server, using 
socket.io, it looks something like this:

socket = io(connectUrl + "?authkey=" + connectKey, {forceNew: true});


:and on the server side, there is something that looks like this


oServer = new IOServer(server);
ioServer.origins(appConfig.origins);
ioServer.use(verifyConnection);
ioServer.on('connection', onConnect);


Notice the verifyConnection middleware being used, that looks like this, 
removing the unimportant bits...


var verifyConnection = function(socket, next) {
    var authkey = socket.request._query.authkey;
    


};




On Saturday, February 20, 2016 at 7:26:54 PM UTC-7, Ray Jender wrote:
>
>
> Please bear with me as I am new to websockets.
>
> So, my problem is keeping track of websocket instances.
> I am trying to modify some existing open source javascript code.
>
> I have server.js, index.js and index.html files. As with any website,
> it could have many users browsing the page. There is only a single
> webpage.
>
> The basic operation is: index.html --> index.js --> server.js --> index.js
>
> What I am having a hard time wrapping my head around is associating the
> websocket with the browser.   What I want to do  is be able to update 
> each webpage with the number of users.  I have googled tons of sites but
> I am still very confused on how this should work.
>
> I've seen a thing like ws.broadcast, but  I am having a hard time trying to
> implement that.  It seems that the way the opensource code I am using 
> initializes
> websockets way different than the examples I am seeing.
>
> I am using node v0.10.42, npm 1.4.29, express 4.12.4, minimist 1.1.1, ws 
> 0.7.2, bower 1.4.1
>
> I need a tutor to help me through this!  Care to volunteer?   I would be 
> so appreciative!!!
>
> Thanks,
>
> Ray
>
>
>

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/c7c25740-c6cd-4767-9a6f-d9b2735d839e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to