I read the doc from Grafana (https://grafana.com/grafana/plugins/golioth-websocket-datasource/?tab=overview) but when I try to replicate it by myself using my locally established WebSockets, it fails to receive data.
Here is what I did:
# ----------- server side: server.py-----------
import asyncio
import websockets
async def echo(websocket, path):
async for message in websocket:
message = "I got your message: {}".format(message)
await websocket.send(message)
asyncio.get_event_loop().run_until_complete(websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()
# ----------- client side: client.py-----------
import asyncio
import websockets
async def hello(uri):
async with websockets.connect(uri) as websocket:
await websocket.send("hello world")
print("< HELLO WORLD")
while True:
recv_text = await websocket.recv()
print("> {}".format(recv_text))
asyncio.get_event_loop().run_until_complete(hello('ws://localhost:8765'))
Run server.py
first and then client.py
,client.py
has the output as below:
< Hello world!
> I got your message: Hello world!
I also configured the host ws://localhost:8765
in Grafana, I suspect I could receive 'hello world'. but didn't receive any data. (table view is toggled)
Wonder if anyone could help?