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):
|
||||
"""hadeler for every new websocket connection"""
|
||||
client = None
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
message = message.split(';')
|
||||
if len(message) == 3 and message[1] == "4675":
|
||||
client = await new_client(message[0], ws)
|
||||
if client is not None:
|
||||
try:
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
message = message.split(';')
|
||||
if len(message) == 3 and message[1] == "4675":
|
||||
client = await new_client(message[0], ws)
|
||||
if client is not None:
|
||||
|
||||
try:
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
if client['state'] == 'active':
|
||||
await on_message(message, client)
|
||||
else:
|
||||
break
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
print("INFO: client " + client['id'] + ": disconnected")
|
||||
client['state'] = "terminated"
|
||||
break
|
||||
elif (len(message) == 3 and message[1] == "3440"):
|
||||
client = await new_boat(message[0], message[2], ws)
|
||||
if client is not None:
|
||||
try:
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
print("boat" + client['id'] + " says '" + message + "'")
|
||||
client['log'].append({
|
||||
"t": datetime.timestamp(datetime.now()),
|
||||
"type": "rx",
|
||||
"msg": message
|
||||
})
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
print("INFO: boat " + client['id'] + ": disconnected")
|
||||
client['state'] = "terminated"
|
||||
break
|
||||
try:
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
if client['state'] == 'active':
|
||||
await on_message(message, client)
|
||||
else:
|
||||
break
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
print("INFO: client " + client['id'] + ": disconnected")
|
||||
client['state'] = "terminated"
|
||||
break
|
||||
elif (len(message) == 3 and message[1] == "3440"):
|
||||
client = await new_boat(message[0], message[2], ws)
|
||||
if client is not None:
|
||||
try:
|
||||
async for msg in ws:
|
||||
for message in msg.split("\n"):
|
||||
if len(message) == 0:
|
||||
continue
|
||||
print("boat" + client['id'] + " says '" + message + "'")
|
||||
client['log'].append({
|
||||
"t": datetime.timestamp(datetime.now()),
|
||||
"type": "rx",
|
||||
"msg": message
|
||||
})
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
print("INFO: boat " + client['id'] + ": disconnected")
|
||||
client['state'] = "terminated"
|
||||
break
|
||||
except websockets.exceptions.ConnectionClosed:
|
||||
print("INFO: connection disconected")
|
||||
|
||||
async def main():
|
||||
"""main"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user