19 lines
492 B
Python
19 lines
492 B
Python
import asyncio
|
|
|
|
|
|
async def tcp_client():
|
|
reader, writer = await asyncio.open_connection(
|
|
'127.0.0.1', 8888)
|
|
|
|
while not writer.is_closing():
|
|
message = input("> ")
|
|
print(f'Send: {message!r}')
|
|
writer.write(message.encode())
|
|
await writer.drain()
|
|
if message == "state":
|
|
data = await reader.read(1000)
|
|
else:
|
|
data = await reader.read(100)
|
|
print(f'Received: {data.decode()!r}')
|
|
|
|
asyncio.run(tcp_client()) |