This commit is contained in:
gjm committed 2026-09-28 22:13:47 +08:00
1 parent 5289689737
commit 1fdcdefef1
2 files changed
+32

No files matched your search

+12
View File
@@ -131,9 +131,20 @@ namespace mcp
bool init_mcp()
{
g_bRunning = true;
try
{
g_serverThread = std::thread(TcpServerLoop);
acutPrintf(_T("\n[MCP Server] 后台 TCP 监听线程已启动 (端口: 8080)...\n"));
}
catch (const std::system_error &e)
{
// 线程创建失败,重置状态标志并输出错误
g_bRunning = false;
// e.what() 返回的是 const char*,所以在 acutPrintf 中要用 %hs 而不是 %s 或 %ls
acutPrintf(_T("\n[MCP Server] 致命错误:无法创建后台监听线程!原因: %hs\n"), e.what());
}
return g_bRunning;
}
bool close_mcp()
{
@@ -143,5 +154,6 @@ namespace mcp
g_serverThread.join();
}
acutPrintf(_T("\n[MCP Server] 插件已卸载,线程已关闭。\n"));
return true;
}
}
+20
View File
@@ -0,0 +1,20 @@
import socket
import json
# 模拟大模型生成的 JSON 指令
command = {
"cmd": "draw_circle",
"x": 500.0,
"y": 500.0,
"r": 250.0
}
try:
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(("127.0.0.1", 8080))
# 发送序列化后的 JSON 字符串
client.sendall(json.dumps(command).encode('utf-8'))
client.close()
print("指令发送成功,请查看 AutoCAD 屏幕。")
except Exception as e:
print(f"连接失败: {e}")