How to check if socket still connected?

I have a page on which users connect to my node server with but I only allow them to have one open connection to the server (by passing along their account id when authorizing them and storing it in an array) and this works fine 99% of the time. The problem is that sometimes when users disconnect, the serverside disconnect event doesn't fire for some reason, so I can't clear their account from the array of clients, which ends up with them being locked out.

Is there a way for me to check if their old socket connection (which I have the ID of) is still active? (So if it isn't I can clear their old connection and let them connect again)


Make sure that heartbeats is set to true (the default). If the timeout lapses, disconnect should happen automatically. However, there was a bug report about heartbeats not working. Make sure you have the latest version of Socket.IO (I'm not sure the status of the bug).

If you still need help, you could send a ping to the old connection when the user tries to reconnect:

Emit a 'ping' from the server, and reply with 'pong' from the client if the connection is still alive. If the ping times out (after say, 20 seconds), drop the connection manually so the user can reconnect. You could use the ping to notify the original client that another client is trying to connect, and raise some UI to that effect.

Need Your Help

How do I search with php sessions using the native_session library in codeigniter

php codeigniter session search native

I just found that i can't use PHPSESSIONS straight away in codeigniter so i've downloaded the Native_Sessions lib for Codeigniter.

How do I detect a palindrome in C?


I've been working through potential interview questions and one of them was to write a function in C to detect whether a given string was a palindrome or not.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.