Socket.io无法从客户端连接到服务器

时间:2017-03-08 05:45:00

标签: node.js sockets socket.io

首先,我的server.js端代码是:

var socket  = require( 'socket.io' );
var requestify = require('requestify');
var express = require('express');
var app     = express();
var server  = require('http').createServer(app);
var io      = socket.listen( server );
var port    = process.env.PORT || 3000;

server.listen(port, function () {
 console.log('Server listening at port %d', port);
});

但是,此服务器代码在分配的端口中运行良好。

现在我的客户端代码是:

var socket = io.connect( 'http://'+IP_ADDRESS+':3000',          {query:'userId='+userId+'&orgId='+orgId});
 console.log(socket);
 socket.on('connect', function() {
        console.log('check 2', socket.connected);
            // alert(socket.connected);
        });

实时服务器 <无效,但在本地(xampp)服务器上工作正常。 socket.on函数没有响应。在控制台日志上 套接字控制台给出:

socket.io-client:url parse http://52.40.237.147:3000 +0ms
2017-03-08 11:20:59.026 socket.io.js:2708 socket.io-client new io 
instance for http://52.40.237.147:3000 +1ms
2017-03-08 11:20:59.030 socket.io.js:2708 socket.io-client:manager
readyState closed +2ms
2017-03-08 11:20:59.030 socket.io.js:2708 socket.io-client:manager 
opening http://52.40.237.147:3000 +3ms
2017-03-08 11:20:59.032 socket.io.js:2708 engine.io-client:socket 
creating transport "polling" +0ms
2017-03-08 11:20:59.034 socket.io.js:2708 engine.io-client:polling 
polling +1ms
2017-03-08 11:20:59.034 socket.io.js:2708 engine.io-client:polling-xhr 
xhr poll +1ms
2017-03-08 11:20:59.036 socket.io.js:2708 engine.io-client:polling-xhr 
xhr open 
GET: http://52.40.237.147:3000/socket.io/?    userId=9&orgId=3&EIO=3&transport=polling&t=LgiQhOy +1ms
2017-03-08 11:20:59.037 socket.io.js:2708 engine.io-client:polling-xhr 
xhr data null +1ms
2017-03-08 11:20:59.039 socket.io.js:2708 engine.io-client:socket 
setting transport polling +3ms
2017-03-08 11:20:59.040 socket.io.js:2708 socket.io-client:manager 
connect attempt will timeout after 20000 +9ms
2017-03-08 11:20:59.041 socket.io.js:2708 socket.io-client:manager 
readyState opening +2ms
2017-03-08 11:20:59.042 (index):1022

伙计们,我无法弄清楚这个问题。为什么它连接到服务器。

0 个答案:

没有答案