套接字IO客户端没有收到任何东西

时间:2013-07-15 15:36:12

标签: node.js sockets socket.io

我正在使用socket io with node来管理聊天应用程序

我可以很容易地连接到我的套接字,但是,当我从其他其他机器连接时,客户端不会回复任何内容。

在其他计算机中,没有禁用防病毒和防火墙。 (我使用谷歌浏览器和歌剧和Windows 7)

非常有趣的是我可以用我的手机连接到socket!

当该机器连接到系统时,我可以在控制台中看到这个调试

 info  - socket.io started
   debug - served static content /socket.io.js
   debug - served static content /socket.io.js
   debug - client authorized
   info  - handshake authorized gu63jD6tYNPCf7JO72U0
   debug - setting request GET /socket.io/1/websocket/gu63jD6tYNPCf7JO72U0
   debug - set heartbeat interval for client gu63jD6tYNPCf7JO72U0
   debug - client authorized for 
   debug - websocket writing 1::
   **debug - websocket writing 5:::{"name":"ready","args":[{"msg":"hi"}]}**
   debug - setting request GET /socket.io/1/xhr-polling/gu63jD6tYNPCf7JO72U0?t=1374596975155
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared heartbeat interval for client gu63jD6tYNPCf7JO72U0
   debug - setting request GET /socket.io/1/jsonp-polling/gu63jD6tYNPCf7JO72U0?t=1374596985158&i=0
   debug - setting poll timeout
   debug - discarding transport
   debug - clearing poll timeout

我用它连接到我的网站:

var socket = io.connect('192.168.1.101:900');

机器没有找到404,或者错误,只是方法没有触发......

正如您所看到的,客户端应该接收 ready ,但它没有得到,问题出在哪里?

服务器来源:

var express = require('/usr/local/lib/node_modules/express'),
        app = express()
        , http = require('http')
        , server = http.createServer(app)
        , io = require('/usr/local/lib/node_modules/socket.io').listen(server);

// listen for new web clients:
server.listen(900, function() {
    //console.log(this);
});


// routing
app.get('/', function(req, res) {
    res.end('It works');
});

io.sockets.on('connection', function(socket) {

    socket.emit('ready', {msg: 'hi'});
}

客户端

    var socket = io.connect('192.168.1.101:900');
    console.log('connecting');

    socket.on('error', function(data) {
        console.log(data || 'error');
    });

    socket.on('connect_failed', function(data) {
        console.log(data || 'connect_failed');
    });

    // on connection to server, ask for user's name with an anonymous callback
    socket.on('connect', function() {

        alert('work');
    });

    socket.on('ready', function() {

        alert('work');
    });

0 个答案:

没有答案