码迷,mamicode.com
首页 > 其他好文 > 详细

负载均衡代码

时间:2017-06-27 10:53:44      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:eal   ring   bre   amr   line   result   using   adk   stream   

    string[] ips = new string[] { "192.168.1.98", "192.168.1.99" };
            for (var i = 0; i < 50; i++)
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + ips[i % 2] + "/server.html");
                request.Host = "serveriphost.demo.com";

                using (WebResponse response = request.GetResponse())
                {
                    Console.Write($"{i.ToString().PadLeft(2, ‘ ‘)}:");

                    using (TextReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        var result = reader.ReadToEnd();

                        if (result != ips[i % 2])
                            Console.WriteLine($"Host:{ips[i % 2]},Real:{result}");
                        else
                            Console.WriteLine("same.");
                    }
                }
            }
            Console.WriteLine("End.");
            Console.ReadKey();

负载均衡代码

标签:eal   ring   bre   amr   line   result   using   adk   stream   

原文地址:http://www.cnblogs.com/kevin1988/p/7083797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!