try to handle overflowing connections

This commit is contained in:
Jakob Ketterl 2019-06-07 20:10:03 +02:00
parent 4b2100b593
commit e8a1a40dc0

View File

@ -38,12 +38,16 @@ class WebSocketConnection(object):
# string-type messages are sent as text frames
if (type(data) == str):
header = self.get_header(len(data), 1)
self.handler.wfile.write(header + data.encode('utf-8'))
self.handler.wfile.flush()
data_to_send = header + data.encode('utf-8')
# anything else as binary
else:
header = self.get_header(len(data), 2)
self.handler.wfile.write(header + data)
data_to_send = header + data
written = self.handler.wfile.write(data_to_send)
if (written != len(data_to_send)):
logger.error("incomplete write! closing socket!")
self.close()
else:
self.handler.wfile.flush()
def read_loop(self):