Hello every one. I try to send json data from my http route which do some logic and after finishing operation send data to websocket channel. This websocket channel send data and frontend listening changes.
@app.route("/text", methods=[“POST”])
async def handler_text(request):
#some logic manipulations
ws = await websockets.client.connect('ws://localhost:5003/backend/alert/message')
print('Connected to alert ws')
await ws.send(json({'message': 'Create new data from db'}))
return response.text("Hello")
@app.websocket("/message")
async def handler_ws(request, ws):
print("Websocket opened")
name = "<someone>"
while True:
data = f"Hello {name}"
await ws.send(data)
name = await ws.recv()
if not name:
break
But when i send post request it’s try to connect but process stopped on connections moment. I try to connect without await and with closing connections after sending data on ‘/test’ endpoint.
How can i send data from my http rout to websocket?