Socket.io随机与SSL断开连接

时间:2015-09-29 14:42:53

标签: javascript node.js sockets ssl socket.io

我对Socket.io和SSL有一个奇怪的问题。我在日志中看到了这一点:

socket.io-parser encoded %j as Object +0ms 2["data",{"data":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAm…CmsTRRQBXkYk06McZoooGTA0uTmiimA7JFNlY4oooAgX7h9zUq/LgCiikBITkCpE9aKKAP/9k=","aspectRatio":0.75,"streamId":"base","timestamp":1443536969377}]
engine.io-client:socket flushing 1 packets in socket +8ms
engine.io-client:socket socket receive: type "message", data "2["data",{"data":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAm…AKGOKKKBlaRjmnRDvRRQBMDxmnA0UUxDgTTZWOKKKBlZfufU1Mp24AoopASE1JH0zRRQB//9k=","aspectRatio":0.75,"streamid":"base"}]" +20ms
socket.io-parser decoded 2["data",{"data":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAm…AKGOKKKBlaRjmnRDvRRQBMDxmnA0UUxDgTTZWOKKKBlZfufU1Mp24AoopASE1JH0zRRQB//9k=","aspectRatio":0.75,"streamid":"base"}] as %j +22ms Object {type: 2, nsp: "/", data: Array[2]}
socket.io-client:socket emitting event %j +27ms ["data", Object]
socket.io-client:manager writing packet %j +60ms Object {type: 2, data: Array[2], nsp: "/"}
socket.io-parser encoding packet %j +37ms Object {type: 2, data: Array[2], nsp: "/"}
socket.io-parser encoded %j as Object +1ms 2["data",{"data":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDACAWGBwYFCAcGhwkIiAm…YmiigCvIxJp0Y4zRRQBMDS5OaKKYDskU2VjiiigCBfuH3NSr8uAKKKQEhOcVInTNFFAH//2Q==","aspectRatio":0.75,"streamId":"base","timestamp":1443536969437}]
engine.io-client:socket flushing 1 packets in socket +39ms
engine.io-client:socket socket close with reason: "transport close" +32ms
socket.io-client:manager close +34ms
socket.io-client:socket close (transport close) +71ms
socket.io-client:manager will wait 762ms before reconnect attempt +0ms
socket.io-client:manager attempting reconnect +764ms
socket.io-client:manager readyState closed +0ms
socket.io-client:manager opening https://server.tld:4003 +0ms
engine.io-client:socket creating transport "polling" +767ms
engine.io-client:polling polling +1ms
engine.io-client:polling-xhr xhr poll +0ms
engine.io-client:polling-xhr xhr open GET: https://server.tld:4003/socket.io/?EIO=3&transport=polling&t=1443536970238-5 +1ms
engine.io-client:polling-xhr xhr data null +0ms
engine.io-client:socket setting transport polling +1ms
socket.io-client:manager connect attempt will timeout after 20000 +5ms

可以看出,套接字因原因而关闭:运输关闭

这种情况时不时发生,间隔不一致(间隔大小为秒(10-60))。

为什么会这样?日志中没有错误。

实例化服务器的代码:



var fs = require( 'fs' );
var app = require('express')();
var https        = require('https');
https.globalAgent.maxSockets = 20000;
https.globalAgent.keepAlive = true;
var server = https.createServer({
    key: fs.readFileSync('/path/to/key.key'),
    cert: fs.readFileSync('/path/to/crt/.crt'),
    ca: fs.readFileSync('/path/to/ca-bundle.crt'),
    requestCert: false,
    rejectUnauthorized: false
},app);
server.listen(4003);

var io = require('socket.io').listen(server);




当使用此代码交换代码(从而禁用SSL)时,不会出现问题:



var fs = require('fs');
var io = require('socket.io').listen(4002);



 `

0 个答案:

没有答案