how to detect that user's connection is lost in nodejs websocket(ws)

I have already used

ws.on('close',function(){});

but in some case even it is not working like if user network is lost, or LAN has been disconnected. So how can I check if user is connected or not, otherwise I have to delete that user from my user queue but for that I have to again check if he is connected..

You problem is network connection doesn't fire an event.

You can use some kind of tick function and check every given time if a user is connected. It will obviously not run if the client is not online.

I am using jQuery for Ajax clearity.

some thing to the effect of:

(psuedo code):

//Client
function tick(){
var date = new Date();
//I assume you node JS controller will listen to tick
$.post("tick", date ).done(setTimeout(tick,5 *60 *1000));
}

I don't know which DB you are using so I won't post code but you have to do something like saving the last tick there (or on cache/memory/redis should be good for this).

You will then have a function running over users last ticks.