This commit is contained in:
2026-04-16 15:19:48 +08:00
commit 1c892259a9
127 changed files with 17390 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
using WebSocketSharp;
using WebSocketSharp.Server;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
var wssv = new WebSocketServer("ws://0.0.0.0:8080");
wssv.AddWebSocketService<WsHandler>("/ws");
wssv.Start();
Console.WriteLine("WebSocket服务器已启动 ws://localhost:8080/ws");
Console.ReadKey();
wssv.Stop();
}
}
// 处理连接
public class WsHandler : WebSocketBehavior
{
protected override void OnOpen()
{
Console.WriteLine("客户端连接");
}
protected override void OnMessage(MessageEventArgs e)
{
Console.WriteLine($"收到消息: {e.Data}");
}
protected override void OnClose(CloseEventArgs e)
{
Console.WriteLine("客户端断开");
}
}
}