Exemplo n.º 1
0
        static void Main(string[] args)
        {
            LogManager.Configuration ??= new NLog.Config.LoggingConfiguration();

            var tcpProvider = new TcpProvider(NetworkSocket.Create);
            var udpProvider = new UdpProvider(NetworkSocket.Create);

            var watcher = new ActivityWatcher(tcpProvider)
            {
                Interval = 15000,
            };

            // TODO Impl udp transport layer.
            var provider      = new AudioProvider(udpProvider);
            var calls         = new CallController(new KeyContainer(), () => new BridgeRouter(provider));
            var authorization = new AuthorizationController();

            var core = new CoreApi(tcpProvider, new MessageFactory(true));

            new AuthApi(core, authorization);
            new TextApi(core, authorization);
            new CallApi(core, authorization, calls);

            // TODO Impl ping message.
            //watcher.Start();

            // TODO Add network interfaces.
            _ = tcpProvider.StartAsync(new IPEndPoint(IPAddress.Any, 30010));
            _ = udpProvider.StartAsync(new IPEndPoint(IPAddress.Any, 30010));

            Console.WriteLine("Press key:\r\n S - stop\r\n Q - exit");

            while (true)
            {
                var key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.Q:
                    return;

                case ConsoleKey.S:
                    tcpProvider.Stop();
                    udpProvider.Stop();
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void TestDiscover()
        {
            var servers = new Dictionary <string, IPAddress>();

            // Create the provider
            using var provider = new UdpProvider(12345);

            // Create the discovery client
            using var client  = provider.CreateClient();
            client.Discovery += (s, e) =>
            {
                lock (servers)
                {
                    servers[e.Identity] = e.Address;
                }
            };

            // Create the discovery server
            using var server = provider.CreateServer();
            server.Identity  = "TestDiscover";

            // Start discovery
            provider.Start();
            server.Start();
            client.Start();

            // Wait 5 seconds for discovery
            Thread.Sleep(5000);

            // Stop discovery
            provider.Stop();
            server.Stop();
            client.Stop();

            // Verify the server was discovered
            Assert.IsTrue(servers.ContainsKey("TestDiscover"));
        }