Example #1
0
        /// <summary>
        /// Start the API Server
        /// </summary>
        public static void Start()
        {
            AllClients = new ConcurrentDictionary <string, AuthClient>();
            var clientUpdateService = new ClientUpdateService();

            ScreenShareService = new ScreenShareService();
            FileSearchService  = new FileSearchService(Path.Combine(AppEnvironment.DataPath, "fileindex.bin"));
            FileSearchService.Start();
            var port         = (int)Settings.Get("TaskServer").TaskServerPort;
            var cancellation = new CancellationTokenSource();
            var address      = NetworkService.GetAddress();
            var endpoint     = new IPEndPoint(address, port);
            var server       = new WebSocketEventListener(endpoint, new WebSocketListenerOptions
            {
                PingTimeout              = TimeSpan.FromSeconds(15),
                NegotiationTimeout       = TimeSpan.FromSeconds(15),
                WebSocketSendTimeout     = TimeSpan.FromSeconds(15),
                WebSocketReceiveTimeout  = TimeSpan.FromSeconds(15),
                ParallelNegotiations     = Environment.ProcessorCount * 2,
                NegotiationQueueCapacity = 256,
                TcpBacklog = 1000
            });

            server.OnConnect          += HandleConnect;
            server.OnDisconnect       += HandleDisconnect;
            server.OnPlainTextMessage += HandlePlainTextMessage;
            server.OnEncryptedMessage += HandleEncryptedMessage;
            server.OnError            += HandleError;
            server.Start();
            Log("Api Server started at " + address);
        }
Example #2
0
        /// <summary>
        ///     Start the API Server
        /// </summary>
        public static void Start()
        {
            var clientUpdateService = new ClientUpdateService();

            clientUpdateService.Start();
            FileSearchService = new FileSearchService(Path.Combine(AppEnvironment.DataPath, "fileIndex.db"));
            FileSearchService.Start();
            CronJobService = new CronJobService(Path.Combine(AppEnvironment.DataPath, "jobs.json"), Path.Combine(AppEnvironment.DataPath, "scripts"));
            CronJobService.ConfigureJobs();
            var apiPort = (int)Settings.Get("TaskServer").TaskServerPort;

            AllClients         = new ConcurrentDictionary <Guid, AuthClient>();
            ScreenShareService = new ScreenShareService();
            var address         = NetworkService.GetAddress();
            var webCamPort      = (int)Settings.Get("Webcams").WebcamPort;
            var screenSharePort = (int)Settings.Get("ScreenShareService").ScreenSharePort;
            var endPoints       = new List <IPEndPoint>
            {
                new IPEndPoint(address, apiPort),
                new IPEndPoint(address, webCamPort),
                new IPEndPoint(address, screenSharePort)
            };
            var server = new WebSocketEventListener(endPoints, new WebSocketListenerOptions
            {
                PingTimeout              = TimeSpan.FromSeconds(15),
                NegotiationTimeout       = TimeSpan.FromSeconds(15),
                WebSocketSendTimeout     = TimeSpan.FromSeconds(15),
                WebSocketReceiveTimeout  = TimeSpan.FromSeconds(15),
                ParallelNegotiations     = Environment.ProcessorCount * 2,
                NegotiationQueueCapacity = 256,
                TcpBacklog        = 1000,
                OnHttpNegotiation = (request, response) =>
                {
                    if (request.Cookies["ConnectionId"] == null)
                    {
                        response.Cookies.Add(new Cookie("ConnectionId", Guid.NewGuid().ToString()));
                    }
                }
            });

            server.OnConnect          += HandleConnect;
            server.OnDisconnect       += HandleDisconnect;
            server.OnPlainTextMessage += HandlePlainTextMessage;
            server.OnEncryptedMessage += HandleEncryptedMessage;
            server.OnError            += HandleError;
            server.Start();
            Log("Api Server started at " + address);
        }