Thanks for the reply Chris.
One of the confusions I am having is trying to impliment something written
for socket.io to use in ws.
But that said, I do have code to get the authkey, but I am confused how the
authkey can be used to access the webpage?
So for code, I have:
*function nextUniqueId() { idCounter++; return
idCounter.toString();}wss.on('connection', function(ws) { var
sessionId = nextUniqueId(); console.log('Connection received with
sessionId ' + sessionId); var id =
ws.upgradeReq.headers['sec-websocket-key']; console.log('New
Connection id : : ', id);*So sessionid just counts the number of users,
which is what I want to display on all user pages.
Right now, each user webpage is only showing what the total user count is
when the user created the ws.
(1,2,3,4, etc). So the first user is showing 1, the second user is showing
2, and so on,
So I am confused on how the var id above can be used to send data to a
particular webpage (websocket)?
Thanks,
Ray
On Saturday, February 20, 2016 at 11:48:55 PM UTC-5, Christopher Mina wrote:
>
> 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/0b7f961d-35a9-48e4-9dff-d79c9322f9bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.