@@ -69,7 +69,7 @@ def is_asyncio_based(self):
6969
7070 async def connect (self , url , headers = {}, auth = None , transports = None ,
7171 namespaces = None , socketio_path = 'socket.io' , wait = True ,
72- wait_timeout = 1 ):
72+ wait_timeout = 1 , retry = False ):
7373 """Connect to a Socket.IO server.
7474
7575 :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,
105105 connection. The default is 1 second. This
106106 argument is only considered when ``wait`` is set
107107 to ``True``.
108+ :param retry: Apply the reconnection logic if the initial connection
109+ attempt fails. The default is ``False``.
108110
109111 Note: this method is a coroutine.
110112
@@ -147,6 +149,10 @@ async def connect(self, url, headers={}, auth=None, transports=None,
147149 await self ._trigger_event (
148150 'connect_error' , n ,
149151 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
150156 raise exceptions .ConnectionError (exc .args [0 ]) from None
151157
152158 if wait :
@@ -477,7 +483,8 @@ async def _handle_reconnect(self):
477483 auth = self .connection_auth ,
478484 transports = self .connection_transports ,
479485 namespaces = self .connection_namespaces ,
480- socketio_path = self .socketio_path )
486+ socketio_path = self .socketio_path ,
487+ retry = False )
481488 except (exceptions .ConnectionError , ValueError ):
482489 pass
483490 else :
0 commit comments