socket.io连接的多个握手

我正在写一个移动应用程序的服务器,并select使用socket.io从服务器到应用程序的推送通知,但我无法设置socket.io

目前在io.connect(服务器:端口)上启动了无数的握手stream,

debug - client authorized info - handshake authorized HXtC1UPzcsEzO8X7x2B1 debug - client authorized info - handshake authorized aE7hMGDpp5InO1UWx2B2 debug - client authorized info - handshake authorized GBx_3n-8Lvbuo4QJx2B3 debug - client authorized info - handshake authorized tOEl0F5wNlh4xkn1x2B4 debug - client authorized info - handshake authorized K55Oit22yN9JDWxhx2B5 debug - client authorized ... 

我正在使用socket.iotitanium的应用程序的客户端,我不知道是哪一端导致此连接问题。

客户:

 var io = require('socket.io-titanium'); var socket = io.connect('http://myserver.com:3000'); socket.on('connect', function (data){ Ti.API.log("socket.io connected"); }); socket.on('update', function (data){ Ti.API.log(data); }); 

服务器:

 index = fs.readFileSync(__dirname + '/index.html'); var updates = http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(index); }); var io = require('socket.io').listen(updates); var clients = {}; io.sockets.on('connection', function(socket) { console.log("Server Connection Event"); socket.on('i am client', console.log); }); io.set("polling duration", 10); io.set("close timeout", 30); updates.listen(3000, function(){ console.log("Updates listening on port 3000"); console.log(""); }); 

我在一个非常长的stream(100 +)中收到一次“服务器连接事件”

我相信握手的想法是连接只需要每个用户授权和build立一次,直到连接closures。

任何帮助将不胜感激!

您是在本地笔记本电脑上还是通过互联网testing?

如果它通过互联网,那么你的socket.io客户端有可能回落到较早的基于轮询的协议。 例如,如果您的ISP碰巧运行HTTP / 1.0代理,就会发生这种情况。 这样的代理将拒绝在HTTP / 1.1中定义的连接升级,因此Web套接字将失败,您的客户端将回退到较旧的方法,如长轮询等。

如果您在本地笔记本电脑上运行时遇到此问题,可能会出现其他问题。 你能打开Chrome,然后打开开发工具>networking,然后selectWeb套接字filter。 现在导航到您的网站,看看您的networking套接字是否正确build立。