Emit an event to the server. :param event: The event name. It can be any string. The event names ``'connect'``, ``'message'`` and ``'disconnect'`` are reserved and should not be used. :param data: The data to send to the server. Data can b
(self, event, data=None)
| 108 | return self.client.transport() if self.client else '' |
| 109 | |
| 110 | async def emit(self, event, data=None): |
| 111 | """Emit an event to the server. |
| 112 | |
| 113 | :param event: The event name. It can be any string. The event names |
| 114 | ``'connect'``, ``'message'`` and ``'disconnect'`` are |
| 115 | reserved and should not be used. |
| 116 | :param data: The data to send to the server. Data can be of |
| 117 | type ``str``, ``bytes``, ``list`` or ``dict``. To send |
| 118 | multiple arguments, use a tuple where each element is of |
| 119 | one of the types indicated above. |
| 120 | |
| 121 | Note: this method is a coroutine. |
| 122 | |
| 123 | This method schedules the event to be sent out and returns, without |
| 124 | actually waiting for its delivery. In cases where the client needs to |
| 125 | ensure that the event was received, :func:`socketio.SimpleClient.call` |
| 126 | should be used instead. |
| 127 | """ |
| 128 | while True: |
| 129 | await self.connected_event.wait() |
| 130 | if not self.connected: |
| 131 | raise DisconnectedError() |
| 132 | try: |
| 133 | return await self.client.emit(event, data, |
| 134 | namespace=self.namespace) |
| 135 | except SocketIOError: |
| 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. |