#!/usr/bin/env python3 """ 简化版Socket通信测试 测试极简版Socket服务器和客户端 """ import sys import os import time # 添加项目根目录到Python路径 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from src.network_model.simple_socket_client import SimpleQTradeSocketClient def test_simple_socket_communication(): """测试简化版Socket通信""" print("🧪 简化版Socket通信测试") print("=" * 50) # 创建客户端 client = SimpleQTradeSocketClient("127.0.0.1", 8081) try: # 连接测试 if client.connect(): print("✅ 连接成功") # 测试各种消息类型 test_cases = [ ("ping", "Ping测试"), ({"type": "get_server_status"}, "获取服务器状态"), ({"type": "update_kline", "data": {"close": 5.0}}, "K线数据更新"), ({"type": "test_sync", "data": "测试数据"}, "同步消息测试"), ] for message, description in test_cases: print(f"\n🔸 {description}") response = client.send_message_sync(message) print(f"响应: {response}") time.sleep(0.5) print("\n✅ 所有测试完成") else: print("❌ 连接失败") except Exception as e: print(f"❌ 测试过程中发生错误: {e}") finally: client.disconnect() if __name__ == "__main__": test_simple_socket_communication()