일부 채팅 응용 프로그램이 필요한 프로젝트에서 작업 중입니다. 나는 여기에 몇 가지 Node.js를/웹 소켓 버전을 테스트하기로 결정 아파치는 달리node.js 병렬 색상을 처리하는 websocket 채팅
Node.js를가 프로세스를 사용하지 않습니다 http://martinsikora.com/nodejs-and-websocket-simple-chat-tutorial
모든 것이 완벽하게 작동을하지만, 그는 튜토리얼의 마지막에 언급로 각 연결.
7 명의 사용자가 로그인하면 하드 코딩 된 모든 색상이 사용 된 다음 사용자 이름 스타일에 흰색이 사용됩니다.
// 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; });
userName = htmlEntities(message.utf8Data);
// 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.');
두 명의 사용자가 같은 색을 사용하도록 허용 할 수 있습니까? 감사합니다.
.shift() 메서드 대신 .indexOf()를 사용하면 어떻게됩니까? – CBeTJlu4ok