删除旧的main.py文件,将FastAPI应用创建逻辑集中在router/main.py中 添加直接运行router/main.py的支持 更新README.md以反映新的项目结构和使用方式 添加websocket连接测试脚本test_websocket.py
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
# test_websocket.py
|
|
import asyncio
|
|
import websockets
|
|
|
|
async def test_connection():
|
|
uri = "ws://47.101.162.164:9600/ws/node"
|
|
headers = {
|
|
"Authorization": "Bearer family-member-x9"
|
|
}
|
|
|
|
try:
|
|
print(f"Connecting to {uri}...")
|
|
async with websockets.connect(uri, extra_headers=headers) as ws:
|
|
print("✅ Connection successful!")
|
|
print("WebSocket connection established.")
|
|
|
|
# 发送注册消息
|
|
import json
|
|
register_msg = {
|
|
"type": "register",
|
|
"node_id": "test-node",
|
|
"display_name": "Test Node",
|
|
"serves_users": ["test-user"],
|
|
"working_dir": "/tmp",
|
|
"capabilities": ["claude_code", "shell", "file_ops"]
|
|
}
|
|
await ws.send(json.dumps(register_msg))
|
|
print("Sent registration message")
|
|
|
|
# 等待响应
|
|
response = await ws.recv()
|
|
print(f"Received response: {response}")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Connection failed: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_connection()) |