Emit an event to the server and wait for a response. This method issues an emit and waits for the server to provide a response or acknowledgement. If the response does not arrive before the timeout, then a ``TimeoutError`` exception is raised. :param event: The even
(self, event, data=None, timeout=60)
| 131 | pass |
| 132 | |
| 133 | def call(self, event, data=None, timeout=60): |
| 134 | """Emit an event to the server and wait for a response. |
| 135 | |
| 136 | This method issues an emit and waits for the server to provide a |
| 137 | response or acknowledgement. If the response does not arrive before the |
| 138 | timeout, then a ``TimeoutError`` exception is raised. |
| 139 | |
| 140 | :param event: The event name. It can be any string. The event names |
| 141 | ``'connect'``, ``'message'`` and ``'disconnect'`` are |
| 142 | reserved and should not be used. |
| 143 | :param data: The data to send to the server. Data can be of |
| 144 | type ``str``, ``bytes``, ``list`` or ``dict``. To send |
| 145 | multiple arguments, use a tuple where each element is of |
| 146 | one of the types indicated above. |
| 147 | :param timeout: The waiting timeout. If the timeout is reached before |
| 148 | the server acknowledges the event, then a |
| 149 | ``TimeoutError`` exception is raised. |
| 150 | """ |
| 151 | while True: |
| 152 | self.connected_event.wait() |
| 153 | if not self.connected: |
| 154 | raise DisconnectedError() |
| 155 | try: |
| 156 | return self.client.call(event, data, namespace=self.namespace, |
| 157 | timeout=timeout) |
| 158 | except TimeoutError: |
| 159 | raise |
| 160 | except SocketIOError: |
| 161 | pass |
| 162 | |
| 163 | def receive(self, timeout=None): |
| 164 | """Wait for an event from the server. |