Skip to content

Initial reconnect #409

@adriandavidauer

Description

@adriandavidauer

The socketio is not automatically trying to reconnect when there is no Internet connection on the initial connect. I have the following code snippet:

import socketio
sio = socketio.Client()

@sio.event
def connect():
    print("I'm connected!")

@sio.event
def connect_error():
    print("The connection failed!")

@sio.event
def disconnect():
    print("I'm disconnected!")
    
sio.connect(MYSERVER)

It works perfectly if the Internet connection is established by the time of the connect. If it breaks down later it will reconnect, just as intended.

But if there is no Internet connection on the initial connect the following Exception is raised:

Traceback (most recent call last):
  File "pyTest.py", line 18, in <module>
    sio.connect(MYSERVER)
  File "/home/al/anaconda3/envs/socketioTest/lib/python3.6/site-packages/socketio/client.py", line 270, in connect
    six.raise_from(exceptions.ConnectionError(exc.args[0]), None)
  File "<string>", line 2, in raise_from
socketio.exceptions.ConnectionError: Connection refused by the server

The behavior should be that it tries to reconnect until there it can reach the server.

I worked my way around it by having the connect in a loop with try/except but I feel like this should be shipped with this great library.
Thanks ;)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions