コード例 #1
0
        private static void StartPublisherClient(CommandLineOptions opts)
        {
            Log.Info("Starting test client as Publisher");
            var             ipAddress = Dns.GetHostEntry(opts.Hostname).AddressList[0];
            PublisherClient publisher = new PublisherClient(ipAddress, opts.Port);

            publisher.Connect();
            publisher.Publish("test-channel");

            Log.Info("Starting client publisher loop");
            while (true)
            {
                var newLine      = Console.ReadLine();
                var newLineSplit = newLine.Split(' ');

                if (newLineSplit[0] == "dispose")
                {
                    publisher.Dispose();
                    break;
                }
                else if (newLineSplit[0] == "publish" && newLineSplit.Length > 1)
                {
                    publisher.Publish(newLineSplit[1]);
                }
                else if (newLineSplit[0] == "unpublish" && newLineSplit.Length > 1)
                {
                    publisher.Unpublish(newLineSplit[1]);
                }
                else
                {
                    publisher.Send(newLine);
                }
            }
            Log.Info("PublisherClient test program complete");
            Console.ReadKey();
        }