I was successful in sending a message repeatedly from a python client to the phoenix channel.
#!/usr/bin/env python
import asyncio
import websockets
import json
async def hello():
async with websockets.connect('ws://127.0.0.1:4000/socket/websocket') as websocket:
data = dict(topic="users:my_token", event="phx_join", payload={}, ref=None)
await websocket.send(json.dumps(data))
# print("joined")
#greeting = await websocket.recv()
print("Joined")
while True:
msg = dict(topic="users:my_token", event="shout", payload={"body":"tworitdash"}, ref=None)
await websocket.send(json.dumps(msg))
call = await websocket.recv()
print("< {}".format(call))
asyncio.get_event_loop().run_until_complete(hello())
asyncio.get_event_loop().run_forever()
But I donโt understand the argument called ref
here. What does that mean and what it should be? I am sending a None
all the time. Thank you in advance ! And I will try to make the communication bidirectional for the python client.