Skip to content

Commit ae6ee7f

Browse files
authored
Merge pull request #43 from charlielito/patch-2
python 2.7 crashes handling error ConnectionResetError
2 parents 99d36b0 + a1bdde5 commit ae6ee7f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

websocket_server/websocket_server.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from base64 import b64encode
77
from hashlib import sha1
88
import logging
9+
from socket import error as SocketError
10+
import errno
911

1012
if sys.version_info[0] < 3:
1113
from SocketServer import ThreadingMixIn, TCPServer, StreamRequestHandler
@@ -189,10 +191,13 @@ def read_bytes(self, num):
189191
def read_next_message(self):
190192
try:
191193
b1, b2 = self.read_bytes(2)
192-
except ConnectionResetError:
193-
logger.info("Client closed connection.")
194-
self.keep_alive = 0
195-
return
194+
except SocketError as e: # to be replaced with ConnectionResetError for py3
195+
if e.errno == errno.ECONNRESET:
196+
logger.info("Client closed connection.")
197+
print("Error: {}".format(e))
198+
self.keep_alive = 0
199+
return
200+
b1, b2 = 0, 0
196201
except ValueError as e:
197202
b1, b2 = 0, 0
198203

0 commit comments

Comments
 (0)