properly close server on disconnection by using sockets