2012-03-28 77 views
0

我使用socket.io创建了一个简单的聊天室。我有我的index.html这些脚本:Socket.io不能在网络中工作

var socket = io.connect('http://imageworkz.asia:8080'); 

    // on connection to server, ask for user's name with an anonymous callback 
    socket.on('connect', function(){ 
     // call the server-side function 'adduser' and send one parameter (value of prompt) 
     socket.emit('adduser', prompt("What's your name?")); 
    }); 

    // listener, whenever the server emits 'updatechat', this updates the chat body 
    socket.on('updatechat', function (username, data) { 
     $('#conversation').append('<b>'+username + ':</b> ' + data + '<br>'); 
    }); 

    // listener, whenever the server emits 'updateusers', this updates the username list 
    socket.on('updateusers', function(data) { 
     $('#users').empty(); 
     $.each(data, function(key, value) { 
      $('#users').append('<div>' + key + '</div>'); 
     }); 
    }); 

    // on load of page 
    $(function(){ 
     // when the client clicks SEND 
     $('#datasend').click(function() { 
      var message = $('#data').val(); 
      $('#data').val(''); 
      // tell server to execute 'sendchat' and send along one parameter 
      socket.emit('sendchat', message); 
     }); 

     // when the client hits ENTER on their keyboard 
     $('#data').keypress(function(e) { 
      if(e.which == 13) { 
       $(this).blur(); 
       $('#datasend').focus().click(); 
      } 
     }); 
    }); 

当我更改为http://localhost:8080连接,并使用“节点app.js”在控制台命令,它工作正常启动,但是当我把它上传,并更改为http://imageworkz.asia:8080,它不工作,只要我去url:http://imageworkz.asia:8080。我是否错过了一些东西,或者还有什么我应该做的,以使其在上传时能够正常工作?或者我会去错误的网址?谢谢!

回答

0

尝试将您的node.js版本更新到网上的最新版本(http://imageworkz.asia:8080)。

还要检查网络上是否安装了所有必需的节点模块,并且如果需要,请更改逻辑,使其不要求prompt()传输消息。