Issue with Web Socket API

Hi guys,

I have implemented code to connect to the websocket server as I need to be able to receive messages regarding training etc. The project I am building does not use an SDK but the API directly and is being programmed in Python. The websockets library is websocket-client.

I retrieve the socket token successfully per the docs:

It appears to connect, but the message received is very different from the one in the docs:
> 0{"sid":"EAjjjM8afISrnrdCALAM","upgrades":[],"pingInterval":25000,"pingTimeout":5000}

I wanted to check if this has actually connected properly as I have code that runs every 20 seconds publishing “2” to keep the connection alive but it fails with “connection already closed”


OPEN
0{"sid":"VClc7ylDF9oJNlWLAKPM","upgrades":[],"pingInterval":25000,"pingTimeout":5000}
40
Message received...
Message received...
Sent keepalive
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 1182, in run
    self.function(*self.args, **self.kwargs)
  File "/home/jetson-nano/ei_jetson_trainer/classes/wsockets.py", line 30, in run
    self.ws.send("2")
  File "/home/jetson-nano/.local/lib/python3.6/site-packages/websocket/_app.py", line 205, in send
    "Connection is already closed.")
websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.

Thanks in advance.

Ok not sure what the issue was it has now started working.

3 Likes