Fuyuba Fuyuba - 1 year ago 44
Node.js Question

Socket server is running but client can't connect

I have setup a Node.js server with Socket.io using HTTPS:

var express = require('express');
var app = express();

app.use(express.static(__dirname + '/public'));
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('commercial.key', 'utf8'),
cert: fs.readFileSync('commercial.crt', 'utf8'),
ca: fs.readFileSync('ca_chain.crt', 'utf8')
var server = https.createServer(options, app);
var io = require('socket.io').listen(server);

app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');

io.on('connection', function(client){
//console.log('IO Connection');
var socket_id = client.id;

console.log(socket_id + " connected");

After starting this server, it's running fine. Clients can connect to it. But, after a few hours, new clients can't connect but old clients - the clients connected before - can still interact with the server.

I just have about 200 ccu and I checked RAM, CPU of VPS, all are fine. I also checked the log file and no errors founded.

Client Error

Anyone can tell me that the setup of server is true or any problems?

Answer Source

After some days research, I don't know why but when i change the config of file /etc/security/limits like this:

* soft nofile 65535
* hard nofile 65535
root soft nofile 65535
root hard nofile 65535

My server seem to be working well. I posted to anyone that have the problem like me, but if someone have the explanation please help me.