当前位置: 首页>>代码示例>>C#>>正文


C# Proxy.Stop方法代码示例

本文整理汇总了C#中System.Proxy.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# Proxy.Stop方法的具体用法?C# Proxy.Stop怎么用?C# Proxy.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Proxy的用法示例。


在下文中一共展示了Proxy.Stop方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            IPAddress ip = null;
            int port = 0;

            var p = new OptionSet()
            .Add("a|address=", v => ip = IPAddress.Parse(v))
            .Add("p|port=", v => port = int.Parse(v));

            p.Parse(args);

            var proxy = new Proxy
            {
                ListenToIp = ip,
                ListenOnPort = port
            };
            proxy.Start();

            Console.WriteLine("Proxy is started ans listening on {0}:{1}", proxy.ListenToIp, proxy.ListenOnPort);
            Console.WriteLine("Press 'Q' to stop the proxy");

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey(true);
                    if (key.Key == ConsoleKey.Q)
                    {
                        proxy.Stop();
                        Console.WriteLine("Proxy is stopped");
                        break;
                    }
                }
            }
        }
开发者ID:JuergenGutsch,项目名称:async-proxy,代码行数:35,代码来源:Program.cs

示例2: SendAndReceive

        public void SendAndReceive()
        {
            using (var context = NetMQContext.Create())
            using (var front = context.CreateRouterSocket())
            using (var back = context.CreateDealerSocket())
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                var proxy = new Proxy(front, back);
                Task.Factory.StartNew(proxy.Start);

                using (var client = context.CreateRequestSocket())
                using (var server = context.CreateResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");

                    client.SendFrame("hello");
                    Assert.AreEqual("hello", server.ReceiveFrameString());
                    server.SendFrame("reply");
                    Assert.AreEqual("reply", client.ReceiveFrameString());
                }

                proxy.Stop();
            }
        }
开发者ID:romanros,项目名称:netmq,代码行数:27,代码来源:ProxyTests.cs

示例3: Main

 /// <summary>
 /// Entry point of the application.
 /// </summary>
 static void Main(string[] args)
 {
     try
     {
         IProxy prx = new Proxy();
         var cli = new CommandLine(prx);
         prx.LoadData();
         cli.StartLoop();
         prx.Stop();
     }
     catch(Exception ex)
     {
         Console.WriteLine("The program ended abnormally!");
         Console.WriteLine(ex);
         Console.ReadLine();
     }
 }
开发者ID:Zagrebelin,项目名称:SocksProxy,代码行数:20,代码来源:Program.cs

示例4: Execute

        private void Execute()
        {
            var ip = Settings.Default.ListenIP;
            var port = Settings.Default.ListenPort;

            var proxy = new Proxy
                {
                    ListenToIp = IPAddress.Parse(ip),
                    ListenOnPort = port
                };
            try
            {
                proxy.Start();
            }
            catch (Exception ex)
            {
                proxy.Stop();
                ServiceEventLog.WriteEntry(ex.ToString(), EventLogEntryType.Error);
                Logger.Log(ex);
            }
        }
开发者ID:JuergenGutsch,项目名称:async-proxy,代码行数:21,代码来源:CallProxy.cs

示例5: ControlSocketObservedMessages

        public void ControlSocketObservedMessages()
        {
            using (var context = NetMQContext.Create())
            using (var front = context.CreateRouterSocket())
            using (var back = context.CreateDealerSocket())
            using (var controlPush = context.CreatePushSocket())
            using (var controlPull = context.CreatePullSocket())
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                controlPush.Bind("inproc://control");
                controlPull.Connect("inproc://control");

                var proxy = new Proxy(front, back, controlPush);
                Task.Factory.StartNew(proxy.Start);

                using (var client = context.CreateRequestSocket())
                using (var server = context.CreateResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");

                    client.SendFrame("hello");
                    Assert.AreEqual("hello", server.ReceiveFrameString());
                    server.SendFrame("reply");
                    Assert.AreEqual("reply", client.ReceiveFrameString());
                }

                Assert.IsNotNull(controlPull.ReceiveFrameBytes());     // receive identity
                Assert.IsEmpty(controlPull.ReceiveFrameString()); // pull terminator
                Assert.AreEqual("hello", controlPull.ReceiveFrameString());

                Assert.IsNotNull(controlPull.ReceiveFrameBytes());     // receive identity
                Assert.IsEmpty(controlPull.ReceiveFrameString()); // pull terminator
                Assert.AreEqual("reply", controlPull.ReceiveFrameString());

                proxy.Stop();
            }
        }
开发者ID:romanros,项目名称:netmq,代码行数:40,代码来源:ProxyTests.cs

示例6: StoppingProxyDisengagesFunctionality

        public void StoppingProxyDisengagesFunctionality()
        {
            using (var context = NetMQContext.Create())
            using (var front = context.CreateRouterSocket())
            using (var back = context.CreateDealerSocket())
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                var proxy = new Proxy(front, back);
                Task.Factory.StartNew(proxy.Start);

                // Send a message through to ensure the proxy has started
                using (var client = context.CreateRequestSocket())
                using (var server = context.CreateResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");
                    client.SendFrame("hello");
                    Assert.AreEqual("hello", server.ReceiveFrameString());
                    server.SendFrame("reply");
                    Assert.AreEqual("reply", client.ReceiveFrameString());

                    proxy.Stop(); // blocks until stopped

                    using (var poller = new Poller(front, back))
                    {
                        poller.PollTillCancelledNonBlocking();

                        client.SendFrame("anyone there?");

                        // Should no longer receive any messages
                        Assert.IsFalse(server.TrySkipFrame(TimeSpan.FromMilliseconds(50)));

                        poller.CancelAndJoin();
                    }
                }
            }
        }
开发者ID:romanros,项目名称:netmq,代码行数:39,代码来源:ProxyTests.cs

示例7: StartAndStopStateValidation

        public void StartAndStopStateValidation()
        {
            using (var context = NetMQContext.Create())
            using (var front = context.CreateRouterSocket())
            using (var back = context.CreateDealerSocket())
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                var proxy = new Proxy(front, back);
                Task.Factory.StartNew(proxy.Start);

                // Send a message through to ensure the proxy has started
                using (var client = context.CreateRequestSocket())
                using (var server = context.CreateResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");
                    client.SendFrame("hello");
                    Assert.AreEqual("hello", server.ReceiveFrameString());
                    server.SendFrame("reply");
                    Assert.AreEqual("reply", client.ReceiveFrameString());
                }

                Assert.Throws<InvalidOperationException>(proxy.Start);
                Assert.Throws<InvalidOperationException>(proxy.Start);
                Assert.Throws<InvalidOperationException>(proxy.Start);

                proxy.Stop(); // blocks until stopped

                Assert.Throws<InvalidOperationException>(proxy.Stop);
            }
        }
开发者ID:romanros,项目名称:netmq,代码行数:33,代码来源:ProxyTests.cs

示例8: StartAgainAfterStop

        public void StartAgainAfterStop()
        {
            using (var context = NetMQContext.Create())
            using (var front = context.CreateRouterSocket())
            using (var back = context.CreateDealerSocket())
            {
                front.Bind("inproc://frontend");
                back.Bind("inproc://backend");

                var proxy = new Proxy(front, back);
                Task.Factory.StartNew(proxy.Start);

                // Send a message through to ensure the proxy has started
                using (var client = context.CreateRequestSocket())
                using (var server = context.CreateResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");
                    client.Send("hello");
                    Assert.AreEqual("hello", server.ReceiveString());
                    server.Send("reply");
                    Assert.AreEqual("reply", client.ReceiveString());
                }

                proxy.Stop(); // blocks until stopped

                // Start it again
                Task.Factory.StartNew(proxy.Start);

                // Send a message through to ensure the proxy has started
                using (var client = context.CreateRequestSocket())
                using (var server = context.CreateResponseSocket())
                {
                    client.Connect("inproc://frontend");
                    server.Connect("inproc://backend");
                    client.Send("hello");
                    Assert.AreEqual("hello", server.ReceiveString());
                    server.Send("reply");
                    Assert.AreEqual("reply", client.ReceiveString());
                }

                proxy.Stop(); // blocks until stopped
            }
        }
开发者ID:bbqchickenrobot,项目名称:netmq,代码行数:44,代码来源:ProxyTests.cs


注:本文中的System.Proxy.Stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。