2016-02-29 40 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); 
     }); 

插座變量低於相同的變量,我評論了,現在的工作。