(conn)
| 26 | except Exception as e: |
| 27 | logging.error(f"Failed to connect to dispatcher({dpc_ip}:{dpc_port}): {e}") |
| 28 | return None |
| 29 | |
| 30 | def receive_message(conn): |
| 31 | # 首先接收4字节的长度信息 |
| 32 | length_bytes = conn.recv(8) |
| 33 | if not length_bytes: |
| 34 | return None |
| 35 | |
| 36 | # 将网络字节序转换回整数 |
| 37 | message_length = socket.ntohl(int.from_bytes(length_bytes, 'big')) |
| 38 | |
| 39 | # 接收实际数据 |
| 40 | data = b'' |
| 41 | while len(data) < message_length: |
| 42 | chunk = conn.recv(min(message_length - len(data), 4096)) |
| 43 | if not chunk: |
| 44 | return None |
| 45 | data += chunk |
| 46 | |
| 47 | # 解码并解析 JSON 数据为 Python 对象 |
| 48 | return json.loads(data.decode('utf-8')) |
| 49 |
no outgoing calls
no test coverage detected