1
yanjinhui
2025-06-12 0b81608b03c5e1e8a20db987dd04cb45bd94c1ad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using HslCommunication.WebSocket;
using WIDESEAWCS_Core.Helper;
 
namespace WIDESEAWCS_Server.HostedService
{
    public static class WebSocketSetup
    {
        public static void AddWebSocketSetup(this IServiceCollection services)
        {
            if (services == null) throw new ArgumentNullException(nameof(services));
 
            if(AppSettings.Get("WebSocketEnable").ObjToBool())
            {
                int port = AppSettings.Get("WebSocketPort").ObjToInt();
                if (port == 0)
                {
                    port = 9296;
                }
 
                services.AddSingleton(x =>
                {
                    WebSocketServer socketServer = new WebSocketServer();
                    socketServer.ServerStart(port);
                    return socketServer;
                });
            }
        }
    }
}