Skip to content

disconnect problems #431

Closed
Closed
@helxsz

Description

@helxsz

I make a simple example for socket.io. when the client emits the 'disconnect' event, the server side would execute socket.on('disconnect', function(msg) too many times that the server would break down because of ' socket.disconnect(socket.id); '

If I comment that line, there is no errors, so what is the problem ?

code:

var app = require('express').createServer();
var redis = require('redis');
app.listen(3000);
var io = require('socket.io').listen(app);

io.sockets.on('connection',function(socket){
   console.log("Client has connected    id:    "+socket.id+"   ");
  socket.emit('news',{hello:'world'});

  socket.on('disconnect', function(msg)
  {   
      console.log("Client has disconnected    id:    "+socket.id+"   ");
      socket.disconnect(socket.id);   
  }) ;

});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions