/// <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); }
/// <summary> /// Start the API Server /// </summary> public static void Start() { PacketLoader.LoadPackets(); var config = Config.Load(); var clientUpdateService = new UpdateService(); 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 = config.TaskServer.TaskServerPort; AllClients = new ConcurrentDictionary <Guid, AuthClient>(); ScreenShareService = new ScreenShareService(); var address = NetworkService.GetAddress(); var webCamPort = config.Webcams.WebcamPort; var screenSharePort = config.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(2), NegotiationTimeout = TimeSpan.FromSeconds(2), WebSocketSendTimeout = TimeSpan.FromSeconds(2), WebSocketReceiveTimeout = TimeSpan.FromSeconds(2), 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); if (RunningAsService) { AgentClient = new UlteriusAgentClient(); AgentClient.Start(); } }
/// <summary> /// Start the API Server /// </summary> public static void Start() { _bufferPoolSize = 100 * _bufferSize; PacketLoader.LoadPackets(); var config = Config.Load(); var clientUpdateService = new UpdateService(); 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 = config.TaskServer.TaskServerPort; AllClients = new ConcurrentDictionary <Guid, AuthClient>(); ScreenShareService = new ScreenShareService(); var address = NetworkService.GetAddress(); var webCamPort = config.Webcams.WebcamPort; var screenSharePort = config.ScreenShareService.ScreenSharePort; var listenEndPoints = new Uri[] { new Uri($"ws://{address}:{apiPort}"), new Uri($"ws://{address}:{webCamPort}"), new Uri($"ws://{address}:{screenSharePort}") }; var options = new WebSocketListenerOptions { PingMode = PingMode.LatencyControl, NegotiationTimeout = TimeSpan.FromSeconds(30), PingTimeout = TimeSpan.FromSeconds(5), ParallelNegotiations = 16, NegotiationQueueCapacity = 256, BufferManager = BufferManager.CreateBufferManager(_bufferPoolSize, _bufferSize), Logger = NullLogger.Instance, HttpAuthenticationHandler = async(request, response) => { await Task.Delay(TimeSpan.FromMilliseconds(1)); if (request.Cookies["ConnectionId"] == null) { response.Cookies.Add(new Cookie("ConnectionId", Guid.NewGuid().ToString())); } return(true); } }; options.Transports.ConfigureTcp(tcp => { tcp.BacklogSize = 1000; // max pending connections waiting to be accepted tcp.ReceiveBufferSize = _bufferSize; tcp.SendBufferSize = _bufferSize; tcp.LingerState = new LingerOption(true, 0); tcp.NoDelay = true; tcp.IsAsync = true; tcp.ReceiveTimeout = TimeSpan.FromSeconds(1); tcp.SendTimeout = TimeSpan.FromSeconds(3); }); var server = new WebSocketEventListener(listenEndPoints, options); server.OnConnect += HandleConnect; server.OnDisconnect += HandleDisconnect; server.OnPlainTextMessage += HandlePlainTextMessage; server.OnEncryptedMessage += HandleEncryptedMessage; server.OnError += HandleError; server.Start(); Log("Api Server started at " + address); }