I have the following code
var instream = request({url: 'http://ift.tt/19bp8wl'})
var outstream = new stream;
outstream.readable = true;
outstream.writable = true;
var rl = readline.createInterface({
input: instream,
output: outstream,
terminal: false
});
io.sockets.on('connection', function(socket) {
rl.on('line', function(line) {
var data = JSON.parse(line)
...
io.to(socket.id).emit('message', data);
});
socket.on('disconnect', function(disconnect) {
// rl.close();
});
});
The problem I face is that even when the clients are correctly disconnected the rl.on line function is still looping for every user who was once connected to the website.
When I do
rl.close();
on disconnect it does remove the open rl.on but then it closes for all users the data stream since readline is closed globally.
How can I achieve it that the open readline process is stopped for users once they are disconnected from the site?
Aucun commentaire:
Enregistrer un commentaire