How to connect NIS Websocket API?

Hello,
I want to use NIS websocket API by python3.
But there is no library for Python (nem-py not include ws lib).

So I want to write down some code.
I user https://github.com/websocket-client/websocket-client

import websocket
import time
import sys

def on_message(ws, message):
    print(message)

def on_error(ws, error):
    print(error)

def on_close(ws):
    print("### closed ###")

def on_open(ws):
    print("opened")
        time.sleep(1)
        ws.close()

    Thread(target=run).start()

if __name__ == "__main__":
    websocket.enableTrace(True)
    ost = "ws://203.189.96.76:7778/w/messages"
    ws = websocket.WebSocketApp(host,
                                on_message=on_message,
                                on_error=on_error,
                                on_close=on_close)
    ws.on_open = on_open
    ws.run_forever()

log

--- request header ---
GET /w/messages HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: 203.189.96.76:7778
Origin: http://203.189.96.76:7778
Sec-WebSocket-Key: Fg8DDS/GZOkCMz4epaRVew==
Sec-WebSocket-Version: 13

-----------------------
--- response header ---
HTTP/1.1 200 OK
Date: Sun, 10 Sep 2017 08:02:06 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Content-Type
Content-Type: text/plain;charset=UTF-8
Content-Length: 19
Server: Jetty(9.2.11.v20150529)
-----------------------
Handshake status 200

Not HTTP/1.1 101.
Is there any good examples? I want to use python.

I find another way.
Thank you. :wink:

hi,

NEM uses STOMP over WebSockets, I suggest you to check this web http://jmesnil.net/stomp-websocket/doc/.

Python STOMP Library https://pypi.python.org/pypi/stompy

1 Like

I should use STOMP instead of SocketJS?
I understand, I will do that next. :grinning:

Thank you!

1 Like