我有一个 socket.io 服务器和一个正确运行的客户端。每次服务器关闭时,客户端每 5 秒尝试重新连接一次。当服务器再次启动时,它们可以毫无问题地连接。
但是当我再次启动服务器之前等待很长时间时,问题就出现了,当服务器启动时,它崩溃显示:
info - socket.io started
debug - client authorized
info - handshake authorized DqN4t2YVP7NiqQi8zer9
debug - setting request GET /socket.io/1/websocket/DqN4t2YVP7NiqQi8zer9
debug - set heartbeat interval for client DqN4t2YVP7NiqQi8zer9
debug - client authorized for
debug - websocket writing 1::
buffer.js:287
pool = new SlowBuffer(Buffer.poolSize);
^
RangeError: Maximum call stack size exceeded
客户端重新连接(未连接时每 5 秒执行一次):
function socket_connect() {
if (!socket) {
socket = io.connect('http://192.168.1.25:8088', { 'reconnect':false, 'connect timeout': 5000 });
} else {
socket.socket.connect();
}
socket.on("connect", function () {
clearInterval(connect_interval);
connect_interval = 0;
socket.emit('player', { refresh_data:true });
});
}
在服务器端,仅使用套接字实例,它会崩溃:
var io = require('socket.io').listen(8088);
我认为问题在于:
当服务器启动时,它每 5 秒接收客户端发出的所有连接,(15 小时断开 * 60 m * 60 s / 5 秒重新连接)并崩溃。
我能做些什么来关闭服务器尝试做的连接?
PS:如果我重新加载客户端,然后启动服务器,它可以工作