Remove duplicated code creating listening socket.