asyncio tcp_echo_client example from python.org not working
Posted: Tue Apr 06, 2021 2:33 pm
Hi,
I am trying to run the example listed here
https://docs.python.org/3/library/async ... io-streams
which seems to me it should run in micropython
I must say that the same example blocks indefinitely on ubuntu 20.04 with python 3.8.5. So the python documentation example for streams does not work in any of both platforms
This is the error I get in micropython
I am trying to run the example listed here
https://docs.python.org/3/library/async ... io-streams
which seems to me it should run in micropython
Code: Select all
import network
import machine
import utime as time
import uasyncio as asyncio
async def tcp_echo_client(message):
#reader, writer = await asyncio.open_connection( '127.0.0.1', 8888)
reader, writer = await asyncio.open_connection( '192.168.12.122', 8888)
print('Send: {}'.format(message))
writer.write(message.encode())
await writer.drain()
data = await reader.read(100)
print('Received: '.format(data.decode()))
print('Close the connection')
writer.close()
await writer.wait_closed()
def main():
wlan = network.WLAN(network.STA_IF)
ssid, paswd = open(wifi.txt, tr).readlines()[0].strip().split(,)
wlan.active(True)
wlan.connect(ssid, paswd)
t=time.ticks_ms()
while(not wlan.isconnected()):
time.sleep(0.25)
print(wlan.ifconfig())
asyncio.run(tcp_echo_client('Hello World!'))
if __name__ == __main__:
main()
This is the error I get in micropython
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 40, in <module>
File "<stdin>", line 34, in main
File "uasyncio/core.py", line 1, in run
File "uasyncio/core.py", line 1, in run_until_complete
File "uasyncio/core.py", line 1, in run_until_complete
File "<stdin>", line 13, in tcp_echo_client
File "uasyncio/stream.py", line 1, in drain
OSError: [Errno 104] ECONNRESET