Files
NetVizor/Common.Net/WebSocketConn/Index.cs
T
2025-06-05 07:13:37 +08:00

38 lines
1000 B
C#

using Common.Logger;
namespace Common.Net.WebSocketConn;
// 主程序示例
public class Program
{
public static void Main(string[] args)
{
var wsManager = WebSocketManager.Instance;
try
{
// 启动WebSocket服务器
wsManager.Start("ws://127.0.0.1:8080");
// 注册自定义处理器
wsManager.RegisterHandler("customCommand", async (cmd, socket) =>
{
Log.Information($"处理自定义命令: {cmd.Command}");
await wsManager.SendToClient(socket.ConnectionInfo.Id, new ResponseMessage
{
Type = "customResponse",
Success = true,
Message = "自定义命令处理完成"
});
});
Log.Information("服务器运行中,按任意键退出...");
Console.ReadKey();
}
finally
{
wsManager.Stop();
}
}
}