-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha_client.py
More file actions
31 lines (26 loc) · 1.09 KB
/
a_client.py
File metadata and controls
31 lines (26 loc) · 1.09 KB
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
import asyncio
HOST = 'localhost'
PORT = 1025
async def server_handle(host, port):
outcoming_message = ''
try:
reader, writer = await asyncio.open_connection(host, port)
incoming_message = await reader.read(255)
print('message:', incoming_message.decode())
while outcoming_message != 'exit':
outcoming_message = input('you: ')
writer.write(outcoming_message.encode())
await writer.drain()
incoming_message = await reader.read(255)
print('message:', incoming_message.decode())
if incoming_message.decode() in ("You didn`t confirm your password and will be disconnected.",
"Wrong password! Try again later."):
break
print("Disconnected from server.")
writer.close()
await writer.wait_closed()
except ConnectionRefusedError:
print("Connection impossible.")
except (ConnectionAbortedError, ConnectionResetError):
print("You was disconnected from server.")
asyncio.run(server_handle(HOST, PORT))