【发布时间】:2014-07-06 00:07:47
【问题描述】:
有时我的套接字服务器会引发以下问题:
这里是heroku日志:
heroku[router]: at=error code=H15 desc="Idle connection" method=GET path=/socket.io/1/websocket/RcjG0Zjot1U3uwLWX9SI
host=www.*********.** request_id=69f5aa39-255b-4871-a928-1548ef2fdd4f
fwd="217.200.201.210" dyno=web.1 connect=0 service=306473 status=503 bytes=870
我使用的是 socket.io 库版本 0.9.x 和节点 0.8.x。 它托管在激活了 websocket 的 heroku 上(heroku labs:enable websockets -a myapp)。 我没有使用 xhr-polling
这是我实现套接字服务器的方式:
var httpServer = http.createServer(function(request, response) {
var pathname = url.parse(request.url).pathname;
if(pathname == "/") pathname = "index.html";
if(pathname.indexOf("/chat/") != -1 ) pathname = "index.html";
var filename = path.join(process.cwd(), 'public', pathname);
path.exists(filename, function(exists) {
if(!exists) {
response.writeHead(404, { "Content-Type": "text/plain" });
response.write("404 Not Found");
response.end();
return;
}
response.writeHead(200, { 'Content-Type': mime.lookup(filename) });
fs.createReadStream(filename, {
'flags': 'r',
'encoding': 'binary',
'mode': 0666,
'bufferSize': 4 * 1024
}).addListener("data", function(chunk) {
response.write(chunk, 'binary');
}).addListener("close", function() {
response.end();
});
});
});
socket_calls = new socket_calls(webSocket, io, connectedUsers,clients );
webSocket.sockets.on('connection',socket_calls.socket_callback_func );
httpServer.listen(process.env.PORT || 8080, "0.0.0.0");
这个问题似乎只存在于 3g 连接上,并且是一些系统无法连接到服务器的客户端报告的。
我尝试在几台具有 3g 连接和 wi-fi 连接的设备上使用“网络链接调节器”模拟连接不良,但无法重现该错误。
【问题讨论】:
-
那么你的问题在哪里?你想怎么做?我认为总是有坏客户,并非总是可以解决它们。如果没有收到心跳,socket.io 应该重新连接。
-
奇怪的是,一旦设备无法连接,就无法系统连接。同一台设备3g连不上,但是wifi能连上,然后在3g上重新测试一次就连不上了。
-
这可能是由于丢包率高造成的。在马来西亚,有时当我连接到边缘网络时,数据包丢失足以让我保持连接但无法完成任何事情。这里可能就是这种情况。用户连接并获取文件和东西。但是中间丢包变高了,TCP socket仍然存在,假装连接,但是高丢包阻止了任何东西通过。
-
大家好,我也遇到了这个问题,经过大量测试和调试后,我意识到这只是 Heroku 路由器的“事情”,因为我的应用程序运行良好,但我一直收到这些错误.我不想重复答案,所以我会把链接留在这里,以防它对任何人都有用 stackoverflow.com/questions/32728030/…