Send a single REQUEST message (no retry). Args: request_id: Unique request identifier. command: Command name. params: Command parameters. timeout_ms: Command timeout in milliseconds. Returns: Response data dictionary.
(
self,
request_id: str,
command: str,
params: dict[str, Any],
timeout_ms: int,
)
| 286 | time.sleep(backoff_ms / 1000) |
| 287 | |
| 288 | def _send_request_once( |
| 289 | self, |
| 290 | request_id: str, |
| 291 | command: str, |
| 292 | params: dict[str, Any], |
| 293 | timeout_ms: int, |
| 294 | ) -> dict[str, Any]: |
| 295 | """Send a single REQUEST message (no retry). |
| 296 | |
| 297 | Args: |
| 298 | request_id: Unique request identifier. |
| 299 | command: Command name. |
| 300 | params: Command parameters. |
| 301 | timeout_ms: Command timeout in milliseconds. |
| 302 | |
| 303 | Returns: |
| 304 | Response data dictionary. |
| 305 | """ |
| 306 | message: dict[str, Any] = { |
| 307 | "type": "REQUEST", |
| 308 | "id": request_id, |
| 309 | "command": command, |
| 310 | "params": params, |
| 311 | "timeout_ms": timeout_ms, |
| 312 | "ts": int(time.time() * 1000), |
| 313 | } |
| 314 | |
| 315 | if self.instance: |
| 316 | message["instance"] = self.instance |
| 317 | |
| 318 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 319 | |
| 320 | try: |
| 321 | try: |
| 322 | sock.settimeout(self.timeout) |
| 323 | sock.connect((self.host, self.port)) |
| 324 | except OSError as e: |
| 325 | raise ConnectionError( |
| 326 | f"Cannot connect to Relay Server at {self.host}:{self.port}.\n" |
| 327 | "Please ensure the relay server is running:\n" |
| 328 | " $ python -m relay.server --port 6500", |
| 329 | "CONNECTION_FAILED", |
| 330 | ) from e |
| 331 | |
| 332 | self._write_frame(sock, message) |
| 333 | |
| 334 | try: |
| 335 | response = self._read_frame(sock) |
| 336 | except builtins.TimeoutError as e: |
| 337 | raise TimeoutError( |
| 338 | f"Response timed out for '{command}' (timeout: {self.timeout}s)", |
| 339 | "TIMEOUT", |
| 340 | ) from e |
| 341 | |
| 342 | if self.on_send: |
| 343 | try: |
| 344 | self.on_send(message, response) |
| 345 | except Exception as cb_err: |
no test coverage detected