@@ -69,7 +69,7 @@ def is_asyncio_based(self):
69
69
70
70
async def connect (self , url , headers = {}, auth = None , transports = None ,
71
71
namespaces = None , socketio_path = 'socket.io' , wait = True ,
72
- wait_timeout = 1 ):
72
+ wait_timeout = 1 , retry = False ):
73
73
"""Connect to a Socket.IO server.
74
74
75
75
:param url: The URL of the Socket.IO server. It can include custom
@@ -105,6 +105,8 @@ async def connect(self, url, headers={}, auth=None, transports=None,
105
105
connection. The default is 1 second. This
106
106
argument is only considered when ``wait`` is set
107
107
to ``True``.
108
+ :param retry: Apply the reconnection logic if the initial connection
109
+ attempt fails. The default is ``False``.
108
110
109
111
Note: this method is a coroutine.
110
112
@@ -147,6 +149,10 @@ async def connect(self, url, headers={}, auth=None, transports=None,
147
149
await self ._trigger_event (
148
150
'connect_error' , n ,
149
151
exc .args [1 ] if len (exc .args ) > 1 else exc .args [0 ])
152
+ if retry : # pragma: no cover
153
+ await self ._handle_reconnect ()
154
+ if self .eio .state == 'connected' :
155
+ return
150
156
raise exceptions .ConnectionError (exc .args [0 ]) from None
151
157
152
158
if wait :
@@ -477,7 +483,8 @@ async def _handle_reconnect(self):
477
483
auth = self .connection_auth ,
478
484
transports = self .connection_transports ,
479
485
namespaces = self .connection_namespaces ,
480
- socketio_path = self .socketio_path )
486
+ socketio_path = self .socketio_path ,
487
+ retry = False )
481
488
except (exceptions .ConnectionError , ValueError ):
482
489
pass
483
490
else :
0 commit comments