# simulator_communication **Repository Path**: theyn/simulator_communication ## Basic Information - **Project Name**: simulator_communication - **Description**: 通讯模拟器,批量模拟各种TCP连接状态。验证单片机网络底层的稳定性,资源能否正常释放① 持续正常连接 ② 间隔正常断开重连 ③ 间隔异常断开重连 ④ 半连接断开(连接 → 等待间隔 → 静默丢弃 → 等待间隔 → 重连)(os.close(),socket 完全不发送 FIN/RST,对端毫不知情) - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-04 - **Last Updated**: 2026-06-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## TCP通信模拟器 多客户端连接模拟 & TCP 服务器工具。 --- ### 功能 #### 通信模拟器 (`app/communication_simulator.py`) - 模拟多个 TCP 客户端并发连接到指定服务器 - 四种连接模式:持续正常连接 / 间隔正常断开重连 / 间隔异常断开重连 / 半连接断开 - 从 Excel 文件加载服务器列表 - 实时日志输出,支持十六进制接收数据显示 - IP 过滤:按设备筛选接收数据 - 日志记录到文件 #### TCP 服务器 (`app/tcp_server.py`) - 监听端口,接受客户端连接 - 实时检测客户端断连 - 多端口同时监听 --- ### 配置文件 `appDoc/config/config.txt` ```ini mode_batch:true # 是否是批量模式 simulator:false # 是否开启仿真器 tcp_server:true # 启动通信模拟器时同时启动 TCP 服务器 ``` 当 `tcp_server:true` 时,`communication_simulator.py` 启动后会自动以子进程拉起 `tcp_server.py`。 --- ### 快速开始 ```bash # 安装依赖 pip install -r requirements.txt # 启动通信模拟器 python app/communication_simulator.py # 单独启动 TCP 服务器 python app/tcp_server.py ``` ### 依赖 - Python 3.8+ - PyQt5 - openpyxl - PyInstaller(打包用) ### 项目结构 ``` simulator_communication/ ├── app/ │ ├── communication_simulator.py # 通信模拟器主程序 │ └── tcp_server.py # TCP 服务器主程序 ├── widget/ │ ├── QSS/ # 样式文件 │ ├── image/ # 图标、图片 │ ├── Ui_*.py # pyuic5 生成的 UI 代码 │ └── w_*.ui # Qt Designer 布局文件 ├── appDoc/ │ ├── config/ # 配置文件 │ └── list_server/ # Excel 服务器列表文件 ├── logs/ # 日志记录输出目录 ├── build.py # PyInstaller 打包脚本 └── requirements.txt ``` --- ## 更新记录 ### 2026.06.05 时间间隔精度提升 & 连接稳定性修复 1. 间隔时间支持 0.01s 最小精度(SpinBox 显示两位小数) 2. 类型 1(持续正常连接)的间隔参数改为健康检测周期,可调 3. `_try_connect` 改为非阻塞 + select 轮询,解决连接中点停止崩溃 4. 移除 "秒" 后缀(列头已有) ### 2026.06.04 日志记录 & UI 重构 & 打包 1. 增加日志记录到文件(勾选记录日志,文件名可自定义) 2. 增加 IP 过滤:按设备筛选接收数据 3. 增加显示接收全局开关 4. 子进程启动 TCP 服务器(config.txt 配置) 5. UI 控件迁移到 .ui 文件(w_communication_simulator.ui / w_tcp_server.ui) 6. appDoc 目录外置到 exe 同级,打包脚本重写 7. 统一路径解析(_app_home / _app_resources) 8. TCP 服务器窗口也集成 .ui 文件 ### 2026.06.03 基本功能测试OK 1. 四种连接模式实现 2. 十六进制数据接收显示 3. QSplitter 可拖拽调节日志区域高度 4. exe 运行时资源文件从 sys._MEIPASS 加载 ### 2026.06.03 新建 TCP 通讯模拟器