Cant execute Socket.on('connect',function(){}) for the second time in same page

I am trying to create a simple app with simple logout and login. While logging in am joining the room and while logout am leaving the room with socket.leave('room');

Problem is that if i login again in the same page without refresh, the code inside the socket.on('connect',...) s not getting executing. Please help me to solve this issue

Like Jakub said, the 'connect' event fires when the client makes a connection to the server, not on joining a room. Rooms are an extra namespace on top of the connection. If you want to execute code every time someone joins, the simplest way would be to just have that code run after the socket.join('whatever') call is made.

A bit trickier, though perhaps more encompassing solution would be to attach a handler of some sort for joining a room. I'm not sure off hand if you can do socket.on('join', fn) but give it a shot. If it doesn't work, you should be able to subscribe via the back-end, something like this might work:

socket.manager.store.subscribe('join', function (id, room) {
    //do whatever
});