Async Websocket behaviour - waiting for input to send? #185
Replies: 2 comments 5 replies
-
|
The problem is that Basically what I think you want is to wait for data from your serial device and your client at the same time. The proper way to do this within asyncio would be :
|
Beta Was this translation helpful? Give feedback.
-
|
Hi @miguelgrinberg uart = UART(2, 115200)
async def forwarded_from_uart():
sreader = asyncio.StreamReader(uart)
while True:
res = await sreader.read(2048)
if res is None:
return b''
else:
return res
@app.route('/echo')
@with_websocket
async def echo(request, ws):
while True:
await ws.send(await forwarded_from_uart())So far it works and I can receive the data. @app.route('/echo')
@with_websocket
async def echo(request, ws):
while True:
await ws.send(await forwarded_from_uart())
await forward_to_uart(await ws.receive())with a new async function called I am asking, because when I tried to run this code with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
I use the microdot async websocket to forward serial data to xterm.js and it works very well.
When I set it up so that the websocket only sends data:
then I get a continuous stream of new data and every update will be pushed to the client.
As a next step I tried to allow for data to be received by the websocket and changed the code as follows:
Now I can receive data! But the continuous stream of sent data is interrupted.
From a client perspective I would have to send new signals again and again to receive new data from the websocket.
I assume the way I wrote ws.send and ws.receive inside the while loop is the reason. I don't understand why though.
passthroughis a function that converts Nones tob'':Would appreciate any help.
Beta Was this translation helpful? Give feedback.
All reactions