Пример #1
0
        public static void DelayTransferEchoServer()
        {
            using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                echoServer.Start();

                var listener = new FixedDelayListener(
                    SinkListener.Instance,
                    TimeSpan.FromSeconds(0.5)
                    );
                var connector = new SimpleConnector(echoServer.EndPoint, listener);

                using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector))
                {
                    proxyServer.Start();

                    var block = Encoding.UTF8.GetBytes("Hello world!");

                    using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block))
                    {
                        echoClient.Start();

                        var stopwatch = Stopwatch.StartNew();

                        echoClient.Ping();

                        Console.WriteLine(stopwatch.Elapsed);
                    }
                }
            }
        }
Пример #2
0
        public static void BandwidthThrottlingProxyEcho()
        {
            using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                echoServer.Start();

                var listener = new ThrottlingListener(
                    SinkListener.Instance,
                    10 * 1024 /* 10 Kb/s */
                    );
                var connector = new SimpleConnector(echoServer.EndPoint, listener);

                using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector))
                {
                    proxyServer.Start();

                    var block = Encoding.UTF8.GetBytes(new string('?', 1024));

                    var stopwatch = Stopwatch.StartNew();

                    using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block))
                    {
                        echoClient.Start();

                        for (int i = 0; i < 100; i++)
                        {
                            echoClient.Ping();
                        }
                    }

                    Console.WriteLine(stopwatch.Elapsed);
                }
            }
        }
Пример #3
0
        public void Setup()
        {
            echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0));
            echoServer.Start();

            if (ContinueMode == ContinueMode.Scheduled)
            {
                queue = new BlockingCollection <OperationContinuation>();

                thread = new Thread(() =>
                {
                    foreach (var continuation in queue.GetConsumingEnumerable())
                    {
                        continuation.SetOutcome(OperationOutcome.Continue);
                    }
                });
                thread.Start();
            }

            IListener listener = null;

            switch (ContinueMode)
            {
            case ContinueMode.Continuation:
                listener = new CompletedContinuationListener();
                break;

            case ContinueMode.Scheduled:
                listener = new ScheduledContinuationListener(queue);
                break;
            }

            proxy = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), new SimpleConnector(echoServer.EndPoint, listener));
            proxy.Start();

            var buffer = new byte[BlockSize];

            new Random().NextBytes(buffer);

            echoClient = new EchoPingClient(proxy.EndPoint, buffer);
            echoClient.Start();
        }
Пример #4
0
        private static void SimulateNetworkFailureEchoServer()
        {
            using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                echoServer.Start();

                var configuration = new ChaosConfiguration
                {
                    Reject =
                    {
                        Percentage = 0.5
                    }
                };
                var connector = new ChaosConnector(
                    configuration,
                    new SimpleConnector(echoServer.EndPoint)
                    );

                using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector))
                {
                    proxyServer.Start();

                    var block = Encoding.UTF8.GetBytes("Hello world!");

                    int errors = 0;

                    for (int i = 0; i < 100; i++)
                    {
                        using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block))
                        {
                            echoClient.ExceptionOccured += (s, e) => Interlocked.Increment(ref errors);
                            echoClient.Start();
                            echoClient.Ping();
                        }
                    }

                    Console.WriteLine(errors);
                }
            }
        }
Пример #5
0
        public static void ProxyEcho()
        {
            using (var echoServer = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                echoServer.Start();

                var connector = new SimpleConnector(echoServer.EndPoint);

                using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector))
                {
                    proxyServer.Start();

                    var block = Encoding.UTF8.GetBytes("Hello world!");

                    using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block))
                    {
                        echoClient.Start();

                        echoClient.Ping();
                    }
                }
            }
        }
Пример #6
0
        public static void LoadBalancedProxyEcho()
        {
            using (var echoServer1 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
                using (var echoServer2 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
                    using (var echoServer3 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
                        using (var echoServer4 = new EchoServer(new IPEndPoint(IPAddress.Loopback, 0)))
                        {
                            echoServer1.Start();
                            echoServer2.Start();
                            echoServer3.Start();
                            echoServer4.Start();

                            var connector = new RoundRobinLoadBalancingConnector(
                                echoServer1.EndPoint,
                                echoServer2.EndPoint,
                                echoServer3.EndPoint,
                                echoServer4.EndPoint
                                );

                            using (var proxyServer = new ProxyServer(new IPEndPoint(IPAddress.Loopback, 0), connector))
                            {
                                proxyServer.Start();

                                var block = Encoding.UTF8.GetBytes("Hello world!");

                                for (int i = 0; i < 32; i++)
                                {
                                    using (var echoClient = new EchoPingClient(proxyServer.EndPoint, block))
                                    {
                                        echoClient.Start();

                                        echoClient.Ping();
                                    }
                                }
                            }
                        }
        }