Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有Express和Socket.IO的Node.js拒绝多个连接_Node.js_Express_Socket.io - Fatal编程技术网

带有Express和Socket.IO的Node.js拒绝多个连接

带有Express和Socket.IO的Node.js拒绝多个连接,node.js,express,socket.io,Node.js,Express,Socket.io,我正在尝试使用Express和Socket.IO设置节点web服务器。我有Express working fine的静态页面功能,但是,如果我尝试将Socket.IO客户端连接到服务器,所有后续连接尝试都会被拒绝,并且客户端套接字从不触发connect事件 用于设置服务器的代码: let app = Express(); let port = options.port || 4747; let serverOptions = {}; if ( options.ssl ) { if (

我正在尝试使用Express和Socket.IO设置节点web服务器。我有Express working fine的静态页面功能,但是,如果我尝试将Socket.IO客户端连接到服务器,所有后续连接尝试都会被拒绝,并且客户端套接字从不触发
connect
事件

用于设置服务器的代码:

let app = Express();
let port = options.port || 4747;
let serverOptions = {};

if ( options.ssl ) {
    if ( !options.ssl.key || !options.ssl.cert ) {
        throw "You must specify the path to both the private key file and the certificate in the SSL options";
    }

    console.log( "SSL enabled...loading keyfile and certificate." );
    Object.assign( serverOptions, {
        key: Fs.readFileSync( options.ssl.key ),
        cert: Fs.readFileSync( options.ssl.cert )
    } );
}

webServer.server = Https.createServer( serverOptions, app );

app.use( "/", Express.static( options.webRoot || "www", {
    index: "index.htm"
} ) );

console.log( `Web server listening on port ${ port }...` );
webServer.server.listen( port );
设置套接字的代码(将上述内容作为
WebServer
导入,将SocketIO作为
Io
导入):

我的测试客户机只是:

var s = require( "socket.io-client" )( "https://arcanox.me:4747/" );

s.on( "connect", function() { 
    console.log( "Connected!" );
} );
它从不打印“已连接!”,但在运行时,所有后续的连接尝试(包括仅针对静态内容)都会被拒绝,并被拒绝
ERR\u CONNECTION\u


给出了什么?

您能将io.sockets.on('connection',function(socket){console.log('connected')}事件添加到您的服务器js文件中吗?我可能已经找到了它。出于某种原因,除非我在设置套接字连接侦听器之前放置了
console.log
,否则它不会将任何内容记录到journalctl中(此服务作为systemd服务运行)崩溃时。连接侦听器中存在模块错误,该侦听器在接受连接后立即重新启动节点。
var s = require( "socket.io-client" )( "https://arcanox.me:4747/" );

s.on( "connect", function() { 
    console.log( "Connected!" );
} );