MCPcopy Create free account
hub / github.com/ModelEngine-Group/flexai / receive_message

Function receive_message

GPU-Virtual-Service/gpu-remoting/proxy.py:28–46  ·  view source on GitHub ↗
(conn)

Source from the content-addressed store, hash-verified

26 except Exception as e:
27 logging.error(f"Failed to connect to dispatcher({dpc_ip}:{dpc_port}): {e}")
28 return None
29
30def 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

Callers 1

aysnc_receive_messageMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected