Hello everyone, I'm building some project where I need chat and decided to use node.js/websocket. I'm just started reading documentation and I don't have much experience in working with javascript.
I found this script http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial which works perfect for me. The only thing I stuck with was colors. In the end of the documentation he says: *Node.js unlike Apache doesn't use processes for each connection.* he has hard coded 7 colors in an array which will be assigned to usernames color style, but every connected user takes one color, so I there are more then 7 users at the same time, as he says: *Well, this would probably threw an exception and the server would broke down immediately.* I tested from local machine and every 8th+ users color becomes white. here is the array: > // Array with some colors > var colors = [ 'red', 'green', 'blue', 'magenta', 'purple', 'plum', > 'orange' ]; > // ... in random order > colors.sort(function(a,b) { return Math.random() > 0.5; } ); and here is code where it uses it: > > // get random color and send it back to the user > userColor = colors.shift(); > connection.sendUTF(JSON.stringify({ type:'color', data: > userColor })); > console.log((new Date()) + ' User is known as: ' + userName > + ' with ' + userColor + ' color.'); My question is, whether it is possible or not to somehow allow two (or more) user to use same color. for example, what if I use .indexOf() method instead of .shift() -- Job Board: http://jobs.nodejs.org/ Posting guidelines: 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 post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
