homeassistant-config/playground/asyncio_test.py

25 lines
526 B
Python
Raw Permalink Normal View History

2019-06-01 16:17:51 +02:00
import asyncio
async def tcp_echo_client(message):
reader, writer = await asyncio.open_connection('server', 7072)
print("Connected")
lines = [
"displayattr .*\n".encode(),
"inform on\n".encode(),
]
writer.writelines(lines)
while True:
data = await reader.readline()
data = data.decode()
print("Received line", data)
#asyncio.run(tcp_echo_client('Hello World!'))
loop = asyncio.get_event_loop()
loop.run_until_complete(tcp_echo_client("bla"))
loop.close()