mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect-gui.git
synced 2025-06-24 21:14:12 +08:00
25 lines
663 B
Python
25 lines
663 B
Python
|
import asyncio
|
||
|
import json
|
||
|
|
||
|
HOST = '127.0.0.1'
|
||
|
PORT = 13000
|
||
|
|
||
|
async def send_json_request(data):
|
||
|
reader, writer = await asyncio.open_connection(HOST, PORT)
|
||
|
|
||
|
# 发送JSON数据
|
||
|
writer.write(json.dumps(data).encode('utf-8'))
|
||
|
await writer.drain()
|
||
|
|
||
|
# 异步接收响应数据
|
||
|
response_data = await reader.read(1024)
|
||
|
print(f"Received response: {response_data.decode('utf-8')}")
|
||
|
|
||
|
# 关闭连接
|
||
|
writer.close()
|
||
|
await writer.wait_closed()
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
request_data = {"requestId": "asdasdasd", "type": "service", "component": "_database", "method": "system_info"}
|
||
|
asyncio.run(send_json_request(request_data))
|