![]() |
VOOZH | about |
dotnet add package ColorVision.SocketProtocol --version 1.5.5.3
NuGet\Install-Package ColorVision.SocketProtocol -Version 1.5.5.3
<PackageReference Include="ColorVision.SocketProtocol" Version="1.5.5.3" />
<PackageVersion Include="ColorVision.SocketProtocol" Version="1.5.5.3" />Directory.Packages.props
<PackageReference Include="ColorVision.SocketProtocol" />Project file
paket add ColorVision.SocketProtocol --version 1.5.5.3
#r "nuget: ColorVision.SocketProtocol, 1.5.5.3"
#:package ColorVision.SocketProtocol@1.5.5.3
#addin nuget:?package=ColorVision.SocketProtocol&version=1.5.5.3Install as a Cake Addin
#tool nuget:?package=ColorVision.SocketProtocol&version=1.5.5.3Install as a Cake Tool
版本: 1.5.5.1 | 目标框架: .NET 8.0 / .NET 10.0 Windows
ColorVision.SocketProtocol 是 ColorVision 桌面端的本地 TCP 通信模块。它不是单纯的协议模型库,而是把 Socket 服务启停、JSON/Text 请求分发、SQLite 消息历史、状态栏入口和管理窗口整合在一起的运行时模块。
ISocketJsonHandler / ISocketTextDispatcher 扩展实现SocketManagerWindow 调试窗口| 文件 | 作用 |
|---|---|
SocketManager.cs |
TCP 服务、客户端连接、JSON/Text 分发和收发记录主链 |
SocketManagerWindow.xaml(.cs) |
连接管理、消息查询、过滤、详情查看、复制、重发和删除 |
SocketMessage.cs |
SQLite 持久化实体,记录方向、内容、客户端、事件名、MsgID、响应码 |
SocketMessageManager.cs |
消息数据库初始化、查询、插入、删除和通用查询入口 |
SocketConfig.cs |
服务器启用状态、监听 IP、端口、Buffer 大小、协议模式 |
SocketConfigProvider.cs |
接入设置系统 |
SocketInitializer.cs |
应用初始化时按配置启动服务,并监听启停变化 |
SocketStatusBarProvider.cs |
状态栏连接状态提示和管理窗口入口 |
ISocketJsonHandler.cs |
JSON 请求处理器扩展接口 |
Properties/Resources.*.resx |
管理窗口和设置项多语言资源 |
flowchart LR
Config["SocketConfig"] --> Initializer["SocketInitializer"]
Initializer --> Manager["SocketManager"]
Manager --> Listener["TcpListener"]
Listener --> Client["TcpClient"]
Client --> Mode{"SocketPhraseType"}
Mode -->|Json| JsonDispatcher["SocketJsonDispatcher"]
Mode -->|Text| TextDispatcher["SocketTextDispatcher"]
JsonDispatcher --> Handler["ISocketJsonHandler"]
TextDispatcher --> TextHandler["ISocketTextDispatcher"]
Manager --> Messages["SocketMessageManager"]
Messages --> Db["SocketMessages.db"]
Manager --> Window["SocketManagerWindow"]
Manager --> StatusBar["SocketStatusBarProvider"]
SocketManagerWindow 现在承担日常调试入口,界面按“服务状态、查询过滤、消息工作区”组织,重点能力包括:
Ctrl+F 聚焦过滤框,Esc 清空过滤,F5 重新查询,Ctrl+C 复制选中消息,Delete 删除选中消息当前 JSON 请求和响应模型定义在 SocketManager.cs:
public class SocketRequest : SocketMessageBase
{
public string Params { get; set; }
}
public class SocketResponse : SocketMessageBase
{
public int Code { get; set; }
public string Msg { get; set; }
public dynamic Data { get; set; }
}
其中 SocketMessageBase 包含 Version、MsgID、EventName、SerialNumber。JSON 模式下,SocketJsonDispatcher 会按 EventName 查找对应的 ISocketJsonHandler。
新增 JSON 事件处理时,实现 ISocketJsonHandler 并确保类型能被 AssemblyService.Instance.GetAssemblies() 扫描到:
public class DemoSocketHandler : ISocketJsonHandler
{
public string EventName => "Demo.Event";
public SocketResponse Handle(NetworkStream stream, SocketRequest request)
{
return new SocketResponse
{
Version = request.Version,
MsgID = request.MsgID,
EventName = request.EventName,
SerialNumber = request.SerialNumber,
Code = 0,
Msg = "OK",
Data = new { received = request.Params }
};
}
}
文本模式则实现 ISocketTextDispatcher,由 SocketTextDispatcher 顺序调用。
%AppData%/ColorVision/Config/SocketMessages.dbSocketConfig.InstanceIsServerEnabled、IPAddress、ServerPort、SocketBufferSize、SocketPhraseTypeSocketConfig.IsServerEnabled 驱动,SocketInitializer 和管理窗口都会复用同一份配置dotnet build UI/ColorVision.SocketProtocol/ColorVision.SocketProtocol.csproj -p:Platform=x64
后续优化建议按风险从低到高推进:
| 阶段 | 目标 | 重点 |
|---|---|---|
| P0 稳定性 | 保证服务启停和 TCP 收发更可靠 | 增加取消令牌、防止重复启动、处理 TCP 粘包/半包、统一客户端清理 |
| P1 可观测性 | 让现场调试更快定位问题 | 消息导出、错误统计、连接生命周期事件、状态栏更详细提示 |
| P2 协议化 | 让外部设备对接更稳定 | JSON Schema、版本兼容策略、处理器元数据、错误码规范 |
| P3 性能与容量 | 支持更长时间运行和更大消息量 | UI 分页/增量加载、数据库索引、保留策略、批量写入 |
更详细的路线见文档站:
docs/02-developer-guide/performance/socket-protocol-optimization-roadmap.mddocs/04-api-reference/ui-components/ColorVision.SocketProtocol.md| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 net8.0-windows7.0 is compatible. net9.0-windows net9.0-windows was computed. net10.0-windows net10.0-windows was computed. net10.0-windows7.0 net10.0-windows7.0 is compatible. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.5.5.3 | 93 | 6/11/2026 |
| 1.5.5.2 | 101 | 5/31/2026 |
| 1.5.5.1 | 116 | 4/13/2026 |
| 1.5.4.1 | 120 | 3/31/2026 |
| 1.5.1.1 | 122 | 2/16/2026 |
| 1.4.1.1 | 124 | 2/3/2026 |
| 1.3.10.2 | 131 | 1/29/2026 |
| 1.3.10.1 | 125 | 1/14/2026 |
| 1.3.9.2 | 711 | 12/1/2025 |
| 1.3.9.1 | 320 | 11/16/2025 |
| 1.3.8.4 | 307 | 11/12/2025 |
| 1.3.8.3 | 232 | 9/30/2025 |
| 1.3.8.2 | 226 | 9/29/2025 |
| 1.3.8.1 | 210 | 9/25/2025 |
| 1.3.6.1 | 206 | 9/5/2025 |
| 1.3.5.2 | 252 | 9/3/2025 |
| 1.3.5.1 | 295 | 8/24/2025 |
| 1.3.3.1 | 208 | 8/18/2025 |
| 1.3.2.4 | 219 | 7/15/2025 |
| 1.3.2.3 | 216 | 6/23/2025 |