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