adding check for the undefined connection in socket.js