diff --git a/websockify/websockifyserver.py b/websockify/websockifyserver.py index 74f9f536..0b1e6072 100644 --- a/websockify/websockifyserver.py +++ b/websockify/websockifyserver.py @@ -718,20 +718,25 @@ def start_server(self): be overridden) for each new client connection. """ - if self.listen_fd != None: - lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM) - elif self.unix_listen != None: - lsock = self.socket(host=None, - unix_socket=self.unix_listen, - unix_socket_mode=self.unix_listen_mode, - unix_socket_listen=True) - else: - lsock = self.socket(self.listen_host, self.listen_port, False, - self.prefer_ipv6, - tcp_keepalive=self.tcp_keepalive, - tcp_keepcnt=self.tcp_keepcnt, - tcp_keepidle=self.tcp_keepidle, - tcp_keepintvl=self.tcp_keepintvl) + try: + if self.listen_fd != None: + lsock = socket.fromfd(self.listen_fd, socket.AF_INET, socket.SOCK_STREAM) + elif self.unix_listen != None: + lsock = self.socket(host=None, + unix_socket=self.unix_listen, + unix_socket_mode=self.unix_listen_mode, + unix_socket_listen=True) + else: + lsock = self.socket(self.listen_host, self.listen_port, False, + self.prefer_ipv6, + tcp_keepalive=self.tcp_keepalive, + tcp_keepcnt=self.tcp_keepcnt, + tcp_keepidle=self.tcp_keepidle, + tcp_keepintvl=self.tcp_keepintvl) + except OSError as e: + self.msg("Openening socket failed: %s", str(e)) + self.vmsg("exception", exc_info=True) + sys.exit() if self.daemon: keepfd = self.get_log_fd()