asyncio, server does not call handle_client
Posted: Sat Jul 09, 2022 1:24 pm
Hello ![Smile :)](./images/smilies/icon_e_smile.gif)
It is likely that I am a dummy.
Pyboard series D
MicroPython v1.19.1 on 2022-06-18; PYBD-SF2W with STM32F722IEK
uasyncio version 3
wifi seems to work as expected
When a simple string is sent by another application to the server ( DGRAM) :
- no faults are displayed in the terminal window for the pyboard
- the sending application shows no faults
- so there is no useful action, the print statement is not executed
It is as though the handle_client does nothing.
Several other simple test tasks run as expected.
Snippet -------------------------------------------------------------------------------------------------------------------
Any assistance would be most welcome ![Smile :)](./images/smilies/icon_e_smile.gif)
Regards Andrew
![Smile :)](./images/smilies/icon_e_smile.gif)
It is likely that I am a dummy.
Pyboard series D
MicroPython v1.19.1 on 2022-06-18; PYBD-SF2W with STM32F722IEK
uasyncio version 3
wifi seems to work as expected
When a simple string is sent by another application to the server ( DGRAM) :
- no faults are displayed in the terminal window for the pyboard
- the sending application shows no faults
- so there is no useful action, the print statement is not executed
It is as though the handle_client does nothing.
Several other simple test tasks run as expected.
Snippet -------------------------------------------------------------------------------------------------------------------
Code: Select all
# https://stackoverflow.com/questions/48506460/python-simple-socket-client-server-using-asyncio
async def handle_client(reader:StreamReader,writer :StreamWriter):
print('in handle_client')
request = None
while request != 'quit':
request = (await reader.read(2)).decode('utf8')
print(request)
response = str(eval(request)) + '\n'
writer.write(response.encode('utf8'))
await writer.drain()
await writer.close()
# --------------------------------------------------
async def run_server():
server = await asyncio.start_server(handle_client,local_IP,local_port)
async with server: await server.serve_forever()
#----------------------------------------------------------------------------------
async def main():
asyncio.create_task(task1())
asyncio.create_task(task2())
asyncio.create_task(task3())
asyncio.create_task(task4())
asyncio.create_task(run_server())
while True:
print('IN MAIN ------')
await asyncio.sleep(3)
#-----------------------------------------------------------------------------------
utime.sleep(10) # time for me to reset terminal session
asyncio.run(main()) [/size]
#-------------------------------------------------------------------------------------------------------------------------------
![Smile :)](./images/smilies/icon_e_smile.gif)
Regards Andrew