gs: more error catching
This commit is contained in:
parent
5beb79b51b
commit
3cda1316ae
@ -209,46 +209,49 @@ async def new_boat(boatId, name, ws):
|
|||||||
async def run(ws, path):
|
async def run(ws, path):
|
||||||
"""hadeler for every new websocket connection"""
|
"""hadeler for every new websocket connection"""
|
||||||
client = None
|
client = None
|
||||||
async for msg in ws:
|
try:
|
||||||
for message in msg.split("\n"):
|
async for msg in ws:
|
||||||
if len(message) == 0:
|
for message in msg.split("\n"):
|
||||||
continue
|
if len(message) == 0:
|
||||||
message = message.split(';')
|
continue
|
||||||
if len(message) == 3 and message[1] == "4675":
|
message = message.split(';')
|
||||||
client = await new_client(message[0], ws)
|
if len(message) == 3 and message[1] == "4675":
|
||||||
if client is not None:
|
client = await new_client(message[0], ws)
|
||||||
|
if client is not None:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
for message in msg.split("\n"):
|
for message in msg.split("\n"):
|
||||||
if len(message) == 0:
|
if len(message) == 0:
|
||||||
continue
|
continue
|
||||||
if client['state'] == 'active':
|
if client['state'] == 'active':
|
||||||
await on_message(message, client)
|
await on_message(message, client)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
except websockets.exceptions.ConnectionClosed:
|
except websockets.exceptions.ConnectionClosed:
|
||||||
print("INFO: client " + client['id'] + ": disconnected")
|
print("INFO: client " + client['id'] + ": disconnected")
|
||||||
client['state'] = "terminated"
|
client['state'] = "terminated"
|
||||||
break
|
break
|
||||||
elif (len(message) == 3 and message[1] == "3440"):
|
elif (len(message) == 3 and message[1] == "3440"):
|
||||||
client = await new_boat(message[0], message[2], ws)
|
client = await new_boat(message[0], message[2], ws)
|
||||||
if client is not None:
|
if client is not None:
|
||||||
try:
|
try:
|
||||||
async for msg in ws:
|
async for msg in ws:
|
||||||
for message in msg.split("\n"):
|
for message in msg.split("\n"):
|
||||||
if len(message) == 0:
|
if len(message) == 0:
|
||||||
continue
|
continue
|
||||||
print("boat" + client['id'] + " says '" + message + "'")
|
print("boat" + client['id'] + " says '" + message + "'")
|
||||||
client['log'].append({
|
client['log'].append({
|
||||||
"t": datetime.timestamp(datetime.now()),
|
"t": datetime.timestamp(datetime.now()),
|
||||||
"type": "rx",
|
"type": "rx",
|
||||||
"msg": message
|
"msg": message
|
||||||
})
|
})
|
||||||
except websockets.exceptions.ConnectionClosed:
|
except websockets.exceptions.ConnectionClosed:
|
||||||
print("INFO: boat " + client['id'] + ": disconnected")
|
print("INFO: boat " + client['id'] + ": disconnected")
|
||||||
client['state'] = "terminated"
|
client['state'] = "terminated"
|
||||||
break
|
break
|
||||||
|
except websockets.exceptions.ConnectionClosed:
|
||||||
|
print("INFO: connection disconected")
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
"""main"""
|
"""main"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user