Sorry about that half finished post, my last post was sent prematurely... What I was getting at is that I now have access to the authkey during the setup phase. I can use this auth key to query the database for information about that user and store it. Now I have a way to directly associated the incoming websocket with a specific user.
I'll now store the actual websocket instances in one or more hash maps, and when I need to, for instance, send a single user some information, i can query that websocket via the socketUserId hash map. Or if I want to send everyone a message, I'll loop through a list where I keep a reference to all sockets, and send each one the message individually. This is just one way of doing it. There are other more appropriate pub/sub mechanisms as well you could investigate. Hopefully that helps a little bit. -Chris 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 [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/11b111fd-7e9c-4254-a30a-a6f9a347a3c2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
