2016-02-29 64 views
1

我试图做一个socket.io节点聊天室应用
我的dependices是
[email protected]
[email protected] 在客户端我加入Socket.IO命名空间将无法正常工作

window.onload = function(){ 

     + var socket = io.connect('http://localhost:4000/chat'); 
     var messagesElement = document.getElementById('messages'); 
     var lastMessageElement = null; 

而在服务器端,我添加

- io.sockets.on('connection',function(socket){ 
    + io.of('/chat').on('connection',function(socket){ 

这些更改之前的应用程序工作正常
当我正尝试在服务器 和客户端上使用socket.io命名空间来分隔
不同的应用程序。
它不起作用,我没有找到控制台上的任何错误或错误。

My application's repository link

回答

1

我刚刚发现存在于客户端

 <script> 
window.onload = function(){ 
     + var socket = io.connect('http://localhost:4000/chat'); 
     var socket = io.connect('/chat'); 
      var messagesElement = document.getElementById('messages'); 
      var lastMessageElement = null; 

@@ -36,7 +36,7 @@ window.onload = function(){ 
       lastMessageElement=newMessageElement; 
      } 
    here--> -var socket = io.connect('http://localhost:4000'); 
    +//var socket = io.connect('http://localhost:4000'); 
     socket.on('serverMessage',function(content){ 
      addMessage(content); 
     }); 

插座变量低于相同的变量,我评论了,现在的工作。