MCPcopy Create free account
hub / github.com/miguelgrinberg/python-socketio / connect

Method connect

src/socketio/async_client.py:75–183  ·  view source on GitHub ↗

Connect to a Socket.IO server. :param url: The URL of the Socket.IO server. It can include custom query string parameters if required by the server. If a function is provided, the client will invoke it to obtain the URL each time a

(self, url, headers={}, auth=None, transports=None,
                      namespaces=None, socketio_path='socket.io', wait=True,
                      wait_timeout=1, retry=False)

Source from the content-addressed store, hash-verified

73 return True
74
75 async def connect(self, url, headers={}, auth=None, transports=None,
76 namespaces=None, socketio_path='socket.io', wait=True,
77 wait_timeout=1, retry=False):
78 """Connect to a Socket.IO server.
79
80 :param url: The URL of the Socket.IO server. It can include custom
81 query string parameters if required by the server. If a
82 function is provided, the client will invoke it to obtain
83 the URL each time a connection or reconnection is
84 attempted.
85 :param headers: A dictionary with custom headers to send with the
86 connection request. If a function is provided, the
87 client will invoke it to obtain the headers dictionary
88 each time a connection or reconnection is attempted.
89 :param auth: Authentication data passed to the server with the
90 connection request, normally a dictionary with one or
91 more string key/value pairs. If a function is provided,
92 the client will invoke it to obtain the authentication
93 data each time a connection or reconnection is attempted.
94 :param transports: The list of allowed transports. Valid transports
95 are ``'polling'`` and ``'websocket'``. If not
96 given, the polling transport is connected first,
97 then an upgrade to websocket is attempted.
98 :param namespaces: The namespaces to connect as a string or list of
99 strings. If not given, the namespaces that have
100 registered event handlers are connected.
101 :param socketio_path: The endpoint where the Socket.IO server is
102 installed. The default value is appropriate for
103 most cases.
104 :param wait: if set to ``True`` (the default) the call only returns
105 when all the namespaces are connected. If set to
106 ``False``, the call returns as soon as the Engine.IO
107 transport is connected, and the namespaces will connect
108 in the background.
109 :param wait_timeout: How long the client should wait for the
110 connection. The default is 1 second. This
111 argument is only considered when ``wait`` is set
112 to ``True``.
113 :param retry: Apply the reconnection logic if the initial connection
114 attempt fails. The default is ``False``.
115
116 Note: this method is a coroutine.
117
118 Example usage::
119
120 sio = socketio.AsyncClient()
121 await sio.connect('http://localhost:5000')
122 """
123 if self.connected:
124 raise exceptions.ConnectionError('Already connected')
125
126 self.connection_url = url
127 self.connection_headers = headers
128 self.connection_auth = auth
129 self.connection_transports = transports
130 self.connection_namespaces = namespaces
131 self.socketio_path = socketio_path
132

Calls 5

_get_real_valueMethod · 0.95
_trigger_eventMethod · 0.95
_handle_reconnectMethod · 0.95
disconnectMethod · 0.95
waitMethod · 0.45