3

As far as I understood, websocket is protocol and socketio is library that implements this protocol.

So I decided to move from python websocket-client to python-socketio as it seems easier to implement behaviors with the decorator @sio.on('subject').

I was playing with different parameter to the connect method but I am always getting errors.

Using sio.connect('ws://echo.websocket.org') or sio.connect('http://echo.websocket.org', transports=['websocket']) the error is:

Attempting polling connection to http://echo.websocket.org/socket.io/?transport=polling&EIO=3
Traceback (most recent call last):
  File "/home/lucas/projects/python/py-websockets/client/test.py", line 6, in <module>
    sio.connect('ws://echo.websocket.org')
  File "/home/lucas/.virtualenvs/py-websockets/lib/python3.6/site-packages/socketio/client.py", line 210, in connect
    six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
  File "<string>", line 3, in raise_from
socketio.exceptions.ConnectionError: Unexpected status code 404 in server response

So looking the log I tried sio.connect('http://echo.websocket.org', transports=['websocket'], socketio_path='') but only prints the log Attempting WebSocket connection to ws://echo.websocket.org//?transport=websocket&EIO=3 and then it gets in some kind of infinity loop and never return.

This is the code I am trying:

import socketio

sio = socketio.Client(logger=True, engineio_logger=True)


@sio.on('connect')
def on_connect(*args, **kwargs):
    print(args, kwargs)


if __name__ == '__main__':
    sio.connect('http://echo.websocket.org', transports=['websocket'])
    sio.wait()

lucrib
  • 448
  • 1
  • 9
  • 21

1 Answers1

7

Socket.IO is not an implementation of WebSocket, it is a different protocol that is implemented on top of HTTP and WebSocket both. A Socket.IO client can only connect to a Socket.IO server and viceversa. The WebSocket protocol is incompatible with Socket.IO.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152