Node.js Nodejs&;网袋

Node.js Nodejs&;网袋,node.js,websocket,Node.js,Websocket,我试图将数据从我的浏览器(Chrome)推送到nodejs服务器,但遇到了严重的问题 基本上,我在浏览器中看到了以下代码: <script src="./Socket.IO/socket.io.js"></script> <script> io.setPath('./Socket.IO/'); var socket=new io.Socket('xxx.xxx.xxx.xxx'); socket.on('co

我试图将数据从我的浏览器(Chrome)推送到nodejs服务器,但遇到了严重的问题

基本上,我在浏览器中看到了以下代码:

<script src="./Socket.IO/socket.io.js"></script>
<script>
        io.setPath('./Socket.IO/');

        var socket=new io.Socket('xxx.xxx.xxx.xxx');

        socket.on('connect',function(){
                alert('connect');       
        });
        socket.on('message',function(msg){
                alert('message'+msg);
        });
        socket.on('close',function(){
                alert('close');
        });
        socket.on('disconnect',function(){
                alert('disconnect');
        });
        socket.connect();

</script>
以及以下客户端代码:

<script>
window.onload=function(){
io.setPath('./Socket.IO/');
socket = new io.Socket('localhost', {'port': 8124});
socket.connect();
socket.send('xxx');
}
</script>

window.onload=function(){
io.setPath('./Socket.io/');
socket=new io.socket('localhost',{'port':8124});
socket.connect();
socket.send('xxx');
}
当我在localhost:8124加载客户机代码时,我希望触发某种类型的“clientConnect”事件。我还在套接字对象上发送数据,但服务器上没有显示任何内容。。。完全被难住了。现在看一下如何使用节点websocket服务器()

解决方案:git克隆git://github.com/LearnBoost/Socket.IO.git --递归的


使用--recursive标志。啊

此代码适用于我:

var server = http.createServer(...);    

server.listen(8124);
server = io.listen(server);
server.on('connection', function(client){
    sys.log('client connected');
});
然后在客户端:

io.setPath('/media/js/Socket.IO/');
socket = new io.Socket('localhost', {'port': 8124});
socket.connect();

也许显式端口参数在您的情况下会有所帮助?

这是Chrome的问题:

嘿,谢谢。我尝试了您提供的代码,但在服务器端控制台上没有收到任何消息;(您的节点实例是否有足够的权限打开端口?这可能是示例不起作用的原因。您也可以尝试sudo node server.js,hello world是否起作用?访问-如果没有“hello world”,则问题在于应用程序的服务器部分-使用基本node.js部署。如果是,请先尝试在没有Socket.IO的情况下运行它。还要检查浏览器中的错误控制台:如果其他一些js失败,则可能无法执行连接方法。socket.io中也可能缺少一些文件。现在github下载中缺少这些文件。请尝试执行git签出:git clonegit://github.com/LearnBoost/Socket.IO.git --递归而不是下载zip存档。
var server = http.createServer(...);    

server.listen(8124);
server = io.listen(server);
server.on('connection', function(client){
    sys.log('client connected');
});
io.setPath('/media/js/Socket.IO/');
socket = new io.Socket('localhost', {'port': 8124});
socket.connect();