예제 #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);
        }
예제 #2
0
        public ScreenShareServer(string serverName, SecureString password, IPAddress address, int port)
        {
            if (Environment.OSVersion.Version.Major >= 6)
            {
                SetProcessDPIAware();
            }
            _port       = port;
            _serverName = serverName;
            _password   = password;

            var cancellation = new CancellationTokenSource();
            var endpoint     = new IPEndPoint(address, _port);

            _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
            });
            _connectionHandler = new ConnectionHandler(_serverName, _password, _server);
        }
 public static void SetEvents(WebSocketEventListener server)
 {
     server.OnConnect += (ws) => {
         sockets.Add(ws);
         Console.WriteLine("Connection from " + ws.RemoteEndpoint.ToString());
     };
     server.OnDisconnect += (ws) =>
     {
         sockets.Remove(ws);
         Console.WriteLine("Disconnection from " + ws.RemoteEndpoint.ToString());
     };
     server.OnError += (ws, ex) =>
     {
         Console.WriteLine("Error: " + ex.Message);
     };
     server.OnMessage += (ws, msg) =>
     {
         Console.WriteLine("Message from [" + ws.RemoteEndpoint + "]: " + msg);
         var wsContext = ws;
         //var task = Task.Factory.StartNew(() =>
         //{
         var util = new Utils();
         // util.ProcessMessage(wsContext);
         foreach (var w in sockets)
         {
             if (w != ws)
             {
                 w.WriteString(msg);
             }
         }
         //});
     };
 }
예제 #4
0
        public static void Start()
        {
            AllClients     = new ConcurrentDictionary <string, AuthClient>();
            ApiControllers = new ConcurrentDictionary <string, ApiController>();
            ScreenShare    = new ScreenShare();
            var port         = (int)Settings.Get("TaskServer").TaskServerPort;
            var cancellation = new CancellationTokenSource();
            var endpoint     = new IPEndPoint(IPAddress.Parse(/*NetworkUtilities.GetIPv4Address()*/ "0.0.0.0"), port);
            var server       = new WebSocketEventListener(endpoint, new WebSocketListenerOptions
            {
                SubProtocols             = new[] { "text" },
                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.OnMessage    += HandleMessage;
            server.OnError      += HandleError;
            server.Start();
            Log("Task TServer started at " + endpoint);
        }
예제 #5
0
        /// <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();
            }
        }
예제 #6
0
 public ConnectionHandler(string serverName, SecureString password, WebSocketEventListener server)
 {
     _serverName           = serverName;
     _password             = password;
     Clients               = new ConcurrentDictionary <string, AuthClient>();
     _commandHandler       = new CommandHandler(this);
     _server               = server;
     _server.OnConnect    += HandleConnect;
     _server.OnDisconnect += HandleDisconnect;
     _server.OnMessage    += HandleMessage;
     _server.OnError      += HandleError;
 }
 static void Main(string[] args)
 {
     sockets = new List <WebSocket>();
     using (var server = new WebSocketEventListener(new IPEndPoint(IPAddress.Any, 8001), new WebSocketListenerOptions()
     {
         SubProtocols = new String[] { "123456" }, NegotiationTimeout = TimeSpan.FromSeconds(30)
     }))
     {
         SetEvents(server);
         server.Start();
         Console.ReadKey(true);
         Console.ReadKey(true);
     }
 }
        public static void Start()
        {
            AllClients     = new ConcurrentDictionary <string, AuthClient>();
            ApiControllers = new ConcurrentDictionary <string, ApiController>();
            var settings     = new Settings();
            var port         = settings.Read("TaskServer", "TaskServerPort", 8387);
            var cancellation = new CancellationTokenSource();
            var endpoint     = new IPEndPoint(IPAddress.Parse(NetworkUtilities.GetIPv4Address()), port);
            var server       = new WebSocketEventListener(endpoint);

            server.OnConnect    += HandleConnect;
            server.OnDisconnect += HandleDisconnect;
            server.OnMessage    += HandleMessage;
            server.OnError      += HandleError;
            server.Start();
            Log("Task TServer started at " + endpoint);
        }
        public static void SetEvents(WebSocketEventListener server)
        {
            server.OnConnect += (ws) => {
                sockets.Add(ws);
                Console.WriteLine("Connection from " + ws.RemoteEndpoint.ToString());
            };
            server.OnDisconnect += (ws) =>
            {
                sockets.Remove(ws);
                Console.WriteLine("Disconnection from " + ws.RemoteEndpoint.ToString());
            };
            server.OnError += (ws, ex) =>
            {
                Console.WriteLine("Error: " + ex.Message);
            };
            server.OnMessage += (ws, msg) =>
            {
                var wsContext = ws;
                Console.WriteLine("Message from [" + ws.RemoteEndpoint + "]: " + msg);
                var msgData   = msg.Split(":".ToArray(), StringSplitOptions.RemoveEmptyEntries)[1];
                var msgToSend = string.Empty;
                if (msg.StartsWith("Name"))
                {
                    names.Add(ws.RemoteEndpoint.ToString(), msgData);
                    msgToSend = ComposeMsg(names[ws.RemoteEndpoint.ToString()], "Joined");
                }
                else
                {
                    msgToSend = ComposeMsg(names[ws.RemoteEndpoint.ToString()], msgData);
                }

                //var task = Task.Factory.StartNew(() =>
                //{
                // util.ProcessMessage(wsContext);
                foreach (var w in sockets)
                {
                    if (w != ws)
                    {
                        w.WriteString(msgToSend);
                    }
                }
                //});
            };
        }
예제 #10
0
        /// <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);
        }