2024-08-08 22:23:36 +08:00
|
|
|
|
using Fleck;
|
2024-09-02 23:20:28 +08:00
|
|
|
|
using log4net;
|
2024-08-08 22:23:36 +08:00
|
|
|
|
|
|
|
|
|
namespace Bunny.Service.WebSocket;
|
|
|
|
|
|
|
|
|
|
public static class WebSocketTest
|
|
|
|
|
{
|
2024-09-02 23:20:28 +08:00
|
|
|
|
private static readonly ILog Log = LogManager.GetLogger(typeof(WebSocketTest));
|
|
|
|
|
|
2024-08-08 22:23:36 +08:00
|
|
|
|
public static void Start()
|
|
|
|
|
{
|
2024-09-02 09:31:34 +08:00
|
|
|
|
var webSocketServer = new WebSocketServer("ws://0.0.0.0:8800");
|
2024-08-08 22:23:36 +08:00
|
|
|
|
|
|
|
|
|
webSocketServer.RestartAfterListenError = true;
|
|
|
|
|
webSocketServer.Start(socket =>
|
|
|
|
|
{
|
2024-09-02 23:20:28 +08:00
|
|
|
|
socket.OnOpen = () => Log.Debug("Open!");
|
|
|
|
|
socket.OnClose = () => Log.Debug("Close!");
|
2024-08-08 22:23:36 +08:00
|
|
|
|
socket.OnMessage = message =>
|
|
|
|
|
{
|
2024-09-02 23:20:28 +08:00
|
|
|
|
Log.Debug(message);
|
2024-08-08 22:23:36 +08:00
|
|
|
|
socket.Send(message);
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|