Skip to content

Chris Perez Lab-5/17#4

Open
ckperez wants to merge 3 commits into
sea-401d5-javascript:masterfrom
ckperez:master
Open

Chris Perez Lab-5/17#4
ckperez wants to merge 3 commits into
sea-401d5-javascript:masterfrom
ckperez:master

Conversation

@ckperez
Copy link
Copy Markdown

@ckperez ckperez commented May 17, 2016

No description provided.

Comment thread lib/tcp-server.js
const sockets = [];

server((socket)=>{
socket.ID = 'User' + Math.floor(Math.random() * 1000);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works as far as attaching an unique value to the socket instance. There's always a question as to whether the socket already has a property called ID that's you'd be overwriting. You could test for this (if !socket.ID), check docs, or you could pick a property name that is more specific - like MYAPP_ID. You could also just use a local var with the index of the array like "user " + index. You know index as length -1 after the push.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants