Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constantly Connecting/Disconnecting with socket connection. #48

Open
shreyaso opened this issue Jul 7, 2016 · 7 comments
Open

Constantly Connecting/Disconnecting with socket connection. #48

shreyaso opened this issue Jul 7, 2016 · 7 comments

Comments

@shreyaso
Copy link

shreyaso commented Jul 7, 2016

Hi,
I am using node 4.2 and need to build server that would be connected to a client via socket.
Since the application is not a web, my socket connection is breaking and re-connecting continuously.

Please guide me if i am doing something wrong.
NOTE: I am initializing the socket io in worker.

Thanks in advance.

@indutny
Copy link
Owner

indutny commented Jul 8, 2016

Hello!

Do you have a test case that could be used to reproduce the problem?

Thank you,
Fedor.

@shreyaso
Copy link
Author

shreyaso commented Jul 28, 2016

Dear "indutny",

Sorry for the very delayed response.

But please look below for the server code:

var cluster = require('cluster');
var clusterWorkerSize = require('os').cpus().length;
var sticky = require('sticky-session');

var server = require('http').createServer(function(req, res) {
  res.end('worker: ' + cluster.worker.id);
});


if (!sticky.listen(server, 14001)) {
  console.log('master');
  server.once('listening', function() {

    console.log('server started on 14001 port');
  });

} else {

    console.log('worker: ' + cluster.worker.id);
    var io = require('socket.io')(server);

    io.on('connection', function(socket){

        var userID = socket.id;
        console.log("connected "+userID);

        socket.on('disconnect', function() {

            console.log('Got disconnect!'+userID);
        });

    });

}

But please look below for the client code:

var io = require('socket.io-client');
var serverUrl = 'http://localhost:14001';
var conn = io.connect(serverUrl);


conn.on('connect', function () {
    var sessionId = conn.io.engine.id;
    console.log(sessionId);

});

@shreyaso
Copy link
Author

shreyaso commented Aug 1, 2016

Hi "indutny",

Can you please help me, i am glued in this.

Thnaks

@indutny
Copy link
Owner

indutny commented Aug 2, 2016

Sorry for delay on my side this time. What's expected output of this? This is what I get on the server:

master
server started on 14001 port
worker: 1
worker: 2
worker: 7
worker: 5
worker: 4
worker: 8
worker: 6
worker: 3
connected /#qLNksnI8RLnvwmE1AAAA

@shreyaso
Copy link
Author

shreyaso commented Aug 2, 2016

Hi ,

Your seems to be perfect, but this is what i got from server:

master
server started on 14001 port
worker: 1
worker: 2
worker: 3
worker: 4
connected /#CoOJtqZFJJuT7EqpAAAA
Got disconnect!/#CoOJtqZFJJuT7EqpAAAA
connected /#8L4eJc4MlI52DWziAAAB
Got disconnect!/#8L4eJc4MlI52DWziAAAB
connected /#tYV8z1I9JV86lqoHAAAC
Got disconnect!/#tYV8z1I9JV86lqoHAAAC

and respectively from client is :

CoOJtqZFJJuT7EqpAAAA
8L4eJc4MlI52DWziAAAB
tYV8z1I9JV86lqoHAAAC

@indutny
Copy link
Owner

indutny commented Aug 6, 2016

That's pretty strange. May I ask you to run server with NODE_DEBUG="net cluster child_process" DEBUG="*" env variables and gist the results?

@jqwatson
Copy link

Hi,

I could replicate this behaviour in Node 0.12.4 but found that upgrading to 4.4.7 resolves the issue for me.

Jon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants