added connection handling logic for the chat server into server.js