Listening to adonis Websocket from Python websocket


#1

I have a websocket server in adonis and want to access it using python’s websocket listener.

Is there a way to do so?

If so, please provide as example.

Thanks in advance


#2

Whenever you connect to the websocket server, the connection is considered as a client connection.

AdonisJs does ship with a client implementation for browsers. However for python, you’ll have to write it yourself and here is protocol on how to do it https://github.com/adonisjs/adonis-websocket-protocol/blob/master/README.md


#3

Thank you very much!!! Really enjoyed using adonisjs in production!!

All my projects now use adonis as backend!!


#4

Following is the Python code for a client for the adonis websocket. Just posted it for anyone looking ofr answers, just like me!!!

import json
from websocket import create_connection
ws = create_connection(“ws://link_to_ws_server:port_no/adonis-ws”)
ws.send(json.dumps({
“t”: 1,
“d”: { “topic”: ‘channel_name:topic_name’ }
}))
while True:
result = ws.recv()
result = json.loads(result)
print (“Received ‘%s’” % result)
ws.close()