socket.io与iOS客户端连接Heroku

时间:2015-06-09 17:06:29

标签: ios node.js heroku socket.io

我真的遇到了大麻烦。 我在Heroku上设置了带有Node.js的socket.io(1X dyno * 2),并且iOS应用程序使用socket.io-client-swift连接到Node.js服务器。 大约有10-20个用户连接服务器。 在前10分钟的连接中,一切都很好。然后,连接开始断开然后连接。然后他们重复(断开,连接,断开连接,连接......)。

日志

2015-06-09T16:57:08.193803+00:00 heroku[router]: at=info method=GET path="/socket.io/?transport=polling&device_system_name=iPhone%20OS&locale=zh-Hant&token=fcc8f9de-731f-4e9f-8984-4ef66f35a017&device_system_version=8.1&app_version=1.0.4.26&device_model=iPhone&b64=1" host=test.mygood.com request_id=8b8334e1-4644-43a5-a68f-5374c7158ee5 fwd="58.115.190.26,103.22.201.247" dyno=web.2 connect=1ms service=9ms status=200 bytes=306
2015-06-09T16:57:08.200240+00:00 app[web.2]: token fcc8f9de-731f-4e9f-8984-4ef66f35a017
2015-06-09T16:57:08.231692+00:00 app[web.2]: shake
2015-06-09T16:57:08.231764+00:00 app[web.2]: loop 0
2015-06-09T16:57:08.244560+00:00 app[web.2]: notmatch: 652 75625
2015-06-09T16:57:08.244754+00:00 app[web.2]: loop 1
2015-06-09T16:57:08.257590+00:00 app[web.2]: notmatch: 668 24747
2015-06-09T16:57:08.229925+00:00 app[web.2]: has connected: qyUbFoTi7h9g31mFAAL4 { userId: 793 }
2015-06-09T16:57:08.261104+00:00 app[web.2]: loop 2
2015-06-09T16:57:08.393477+00:00 app[web.1]: 91BXJwsGY4hn6rWNAAKK has disconnected!
2015-06-09T16:56:51.814378+00:00 heroku[router]: at=info method=GET path="/socket.io/?transport=polling&device_system_name=iPhone%20OS&locale=zh-Hant&token=4b6606d4-b569-4eca-ae9d-10a567061c8c&device_system_version=8.3&app_version=1.0.4.26&device_model=iPhone&sid=YOfYOZ2khJ-6mcBnAALi&b64=1" host=test.mygood.com request_id=a11b31aa-1ffb-46de-9de1-305599b5a399 fwd="118.165.42.38,108.162.226.25" dyno=web.2 connect=1ms service=2ms status=400 bytes=228
2015-06-09T16:57:08.572700+00:00 app[web.2]: feTOjlhWmquYCEfjAAJ6 has disconnected!
2015-06-09T16:57:06.770212+00:00 heroku[router]: at=info method=GET path="/socket.io/?transport=websocket&device_system_name=iPhone%20OS&locale=zh-Hant&token=bd06e22e-7175-42ac-88f4-e6e68f449620&device_system_version=8.3&app_version=1.0.4.26&device_model=iPhone&sid=LzZEXe6cINwxDqb_AAMI" host=test.mygood.com request_id=82dc60be-c247-451a-a9e5-120720485620 fwd="27.247.203.209,103.22.200.134" dyno=web.2 connect=1ms service=4ms status=400 bytes=504
2015-06-09T16:57:08.609417+00:00 app[web.1]: shake
2015-06-09T16:57:08.609461+00:00 app[web.1]: loop 0
2015-06-09T16:57:08.968691+00:00 heroku[router]: at=info method=GET path="/socket.io/?transport=polling&device_system_name=iPhone%20OS&locale=zh-Hant&token=bd06e22e-7175-42ac-88f4-e6e68f449620&device_system_version=8.3&app_version=1.0.4.26&device_model=iPhone&b64=1" host=test.mygood.com request_id=84f68bc2-889d-4935-83af-be0ab81a4ce5 fwd="27.247.203.209,103.22.200.83" dyno=web.2 connect=2ms service=2ms status=200 bytes=306
2015-06-09T16:57:08.908175+00:00 heroku[router]: at=info method=GET path="/socket.io/?transport=polling&device_system_name=iPhone%20OS&locale=zh-Hant&token=afd16987-e2ea-446e-999f-e2f61aa0dde5&device_system_version=8.3&app_version=1.0.4.26&device_model=iPhone&b64=1" host=test.mygood.com request_id=e4def746-c8c2-4241-92f0-2236eda03dc3 fwd="223.137.154.167,103.22.200.105" dyno=web.1 connect=2ms service=3ms status=200 bytes=306
2015-06-09T16:57:08.908393+00:00 app[web.1]: token afd16987-e2ea-446e-999f-e2f61aa0dde5
2015-06-09T16:57:08.936892+00:00 app[web.1]: 0CR17CxuaLjrkyZ7AAKL has disconnected!
2015-06-09T16:57:08.922146+00:00 app[web.1]: has connected: 97mC_C_oBgL9j3bPAAMM { userId: 670 }
2015-06-09T16:57:09.094138+00:00 app[web.1]: ZgQnkM0NzTfd0QTgAAKM has disconnected!
2015-06-09T16:57:08.971702+00:00 app[web.2]: token bd06e22e-7175-42ac-88f4-e6e68f449620
2015-06-09T16:57:09.208419+00:00 app[web.2]: token fcc8f9de-731f-4e9f-8984-4ef66f35a017
2015-06-09T16:57:08.984120+00:00 app[web.2]: has connected: Jn9DJKjq5nsQbBxAAAL5 { userId: 652 }
2015-06-09T16:57:09.232017+00:00 app[web.2]: Qis91FslGt1xajvuAAJ7 has disconnected!
2015-06-09T16:57:09.239394+00:00 heroku[router]: at=info method=GET path="/socket.io/?transport=polling&device_system_name=iPhone%20OS&locale=zh-Hant&token=afd16987-e2ea-446e-999f-e2f61aa0dde5&device_system_version=8.3&app_version=1.0.4.26&device_model=iPhone&sid=97mC_C_oBgL9j3bPAAMM&b64=1" host=test.mygood.com request_id=c0c378d9-d836-4afe-b32b-a097037d65c0 fwd="223.137.154.167,103.22.200.105" dyno=web.1 connect=1ms service=2ms status=200 bytes=208
2015-06-09T16:57:09.236929+00:00 app[web.2]: has connected: v2zsDiJGUT3jMdLXAAL6 { userId: 793 }

app.js文件

var io = require('socket.io')(process.env.PORT || 3001);
io.use(function (socket, next){
    var token = socket.request._query.token;

    authorize(token, function(user) {
        .... // some authorization work
        next();
    }, function(error){
        next(new Error('API Token wrong'));
    });
});
io.on('connection', function (socket) {
    console.log('has connected:', socket.id, socket.api);
    socket.on('disconnect', function () {
        console.log(socket.id + ' has disconnected!');
    });
});

0 个答案:

没有答案