Handle disconnects (again)
I had removed disconnect handling when I started the partial rewrite. This commit re-adds it.
This commit is contained in:
parent
d2d3a7c13c
commit
5bc5094593
|
@ -41,11 +41,9 @@ class Client:
|
||||||
client = self
|
client = self
|
||||||
self.server = server
|
self.server = server
|
||||||
self.client = client_
|
self.client = client_
|
||||||
#self.conn = conn
|
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.has_auth = False
|
self.has_auth = False
|
||||||
self.ready_for_msgs = False
|
self.ready_for_msgs = False
|
||||||
print('srfm')
|
|
||||||
self.acked = True
|
self.acked = True
|
||||||
self.version = None
|
self.version = None
|
||||||
self.next_msg = None
|
self.next_msg = None
|
||||||
|
@ -69,6 +67,14 @@ class Client:
|
||||||
self.do_send()
|
self.do_send()
|
||||||
|
|
||||||
|
|
||||||
|
def on_left(client_, server):
|
||||||
|
global client
|
||||||
|
if client_ != client.client:
|
||||||
|
return
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
|
||||||
def on_message(client_, server, message):
|
def on_message(client_, server, message):
|
||||||
global client
|
global client
|
||||||
if client_ != client.client:
|
if client_ != client.client:
|
||||||
|
@ -137,8 +143,14 @@ def get_img_msg():
|
||||||
def cycle():
|
def cycle():
|
||||||
if client is not None:
|
if client is not None:
|
||||||
msg = get_img_msg()
|
msg = get_img_msg()
|
||||||
client.next_msg = msg
|
try:
|
||||||
client.do_send()
|
client.next_msg = msg
|
||||||
|
client.do_send()
|
||||||
|
except AttributeError as e:
|
||||||
|
if "'NoneType' object has no attribute" in str(e):
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
def do_cycles():
|
def do_cycles():
|
||||||
while True:
|
while True:
|
||||||
|
@ -150,4 +162,5 @@ threading.Thread(target=do_cycles).start()
|
||||||
server = WebsocketServer(int(config_data['port']), host='0.0.0.0', loglevel=logging.INFO)
|
server = WebsocketServer(int(config_data['port']), host='0.0.0.0', loglevel=logging.INFO)
|
||||||
server.set_fn_new_client(on_connect)
|
server.set_fn_new_client(on_connect)
|
||||||
server.set_fn_message_received(on_message)
|
server.set_fn_message_received(on_message)
|
||||||
|
server.set_fn_client_left(on_left)
|
||||||
server.run_forever()
|
server.run_forever()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user