A:添加WS服务配置示例

This commit is contained in:
jimmy committed 2025-05-24 23:46:53 +08:00
1 parent 5ed57b1998
commit 7ade2bd437
5 files changed
+462

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
namespace Application.Connections;
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Text.Json;
using Fleck;
using System.Timers;
// 主程序示例
public class Program
{
public static void Main(string[] args)
{
var wsManager = WebSocketManager.Instance;
var networkMonitor = new NetworkMonitorService();
try
{
// 启动WebSocket服务器
wsManager.Start("ws://127.0.0.1:8080");
// 注册自定义处理器
wsManager.RegisterHandler("customCommand", async (cmd, socket) =>
{
Console.WriteLine($"处理自定义命令: {cmd.Command}");
await wsManager.SendToClient(socket.ConnectionInfo.Id, new ResponseMessage
{
Type = "customResponse",
Success = true,
Message = "自定义命令处理完成"
});
});
// 启动网络监控
networkMonitor.StartMonitoring(3000);
Console.WriteLine("服务器运行中,按任意键退出...");
Console.ReadKey();
}
finally
{
networkMonitor.StopMonitoring();
wsManager.Stop();
}
}
}