Ejemplo n.º 1
0
async def websocket_endpoint(websocket: WebSocket):
    websocket.accept()

    try:
        while True:
            data = await websocket.receive_text()

            if data == "97":
                ser.write("a".encode())
                print("a")
            elif data == "98":
                ser.write("b".encode())
                print("b")
            else:
                print("[another commend]", data)

    except WebSocketDisconnect as e:
        print("disconnect", e)
Ejemplo n.º 2
0
async def websocket_endpoint(websocket: WebSocket):
    websocket.accept()
    while True:
        data = await websocket.receive_text()
        await websocket.send_text(f"Message was {data}")