-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
45 lines (31 loc) · 858 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
39
40
41
42
43
44
45
import asyncio
from commons import Commands
HOST = "127.0.0.1"
PORT = 62775
async def send(choice: int):
_, writer = await asyncio.open_connection(HOST, PORT)
writer.write(choice.to_bytes())
await writer.drain()
writer.close()
await writer.wait_closed()
async def main():
print("Options:")
for cmd in Commands:
print(f"{cmd.value}: {cmd.name}")
str_choice = input("Select an option: ")
try:
choice = int(str_choice)
command = Commands(choice)
except ValueError:
print("Invalid option.")
return
print(f"Sending {command.name} to {HOST}:{PORT}.")
try:
await send(choice)
except OSError as error:
print(error.strerror)
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("Aborted.")