How to delete disconnected sockets???
See original GitHub issueI use socket.io version 1.5.1 and I want to delete disconnected sockets, but I don’t find an answer to fix this.
This is the socket server in node
var http = require('http').Server(app);
var io = require('socket.io')(http);
var redis = require('redis').createClient();
redis.subscribe('change-financial-flag');
io.on('connection', function (socket){
console.log("connected user: " + socket.id);
clients.push(socket);
redis.on('message', function(channel, message) {
socket.emit(channel, message);
console.log('emit: ' + channel + ' - socket: ' + socket.id);
});
socket.on('disconnect', function(){
socket.disconnect(true);
console.info('disconnected user (id=' + socket.id + ').');
});
});
http.listen(5001, function () {
console.log('listening on *:5001');
});
This is my output:
connected user: Bso5jOM3BmifSNUgAAAA
disconnected user (id=Bso5jOM3BmifSNUgAAAA).
connected user: yt0sLF5Mm5vts1ujAAAB
disconnected user (id=yt0sLF5Mm5vts1ujAAAB).
connected user: nZWM2gwE6pJXcIjsAAAC
disconnected user (id=nZWM2gwE6pJXcIjsAAAC).
connected user: MKhspxnSpmnxG4nAAAAD
disconnected user (id=MKhspxnSpmnxG4nAAAAD).
connected user: FnvUJsLKjtIC80MvAAAE
emit: change-financial-flag - socket: Bso5jOM3BmifSNUgAAAA
emit: change-financial-flag - socket: yt0sLF5Mm5vts1ujAAAB
emit: change-financial-flag - socket: nZWM2gwE6pJXcIjsAAAC
emit: change-financial-flag - socket: MKhspxnSpmnxG4nAAAAD
emit: change-financial-flag - socket: FnvUJsLKjtIC80MvAAAE
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Remove objects on disconnect socket.io - Stack Overflow
If you don't cleanup, then yes, they will stay there forever since I assume you are making them global. You should cleanup once...
Read more >How to remove disconnected sockets - MSDN - Microsoft
1. Client device make a connection to the server. 2. Sending data every 10 seconds without disconnection. 3. Client device is not concerned ......
Read more >removing a socket from list on disconnect - SFML
removing a socket from list on disconnect. ... if (client.receive(packet) == sf::Socket::Disconnected) {
Read more >Rooms | Socket.IO
Upon disconnection, sockets leave all the channels they were part of automatically, and no special teardown is needed on your part. You can ......
Read more >Deleting clientsocket in slot for signal disconnected ... - Qt Forum
Initially I was deleting the memory for client socket in SlotForDisconnected() using delete <clientSocket_Object> and setting it to NULL ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@darrachequesne Can you help me based in my code?
The problem here is that you keep a reference to the
socket
inredis.on('message', ... )
.