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