示例#1
0
        private static void ClientThread()
        {
            var transport    = new SocketClientTransport("localhost", 4242);
            var client       = new RpcClient(transport);
            var eventHandler = new SettingsEvents_Handler();

            client.AddEventListener(eventHandler);
            eventHandler.Changed += Program.EventHandlerOnChanged;
            var settings = new SettingsService_Proxy(client);

            settings.Set(
                new SettingList
            {
                Item =
                {
                    new Setting()
                    {
                        Key = "Setting 1", Value = "Value one"
                    },
                    new Setting()
                    {
                        Key = "Setting 2", Value = "Value two"
                    },
                    new Setting()
                    {
                        Key = "Setting 3", Value = "Value three"
                    }
                }
            });

            var settingsList = settings.Get(new SettingKeyList {
                Item = { "Setting 1", "Setting 2" }
            });

            foreach (var setting in settingsList.Item)
            {
                Console.WriteLine("{0} = {1}", setting.Key, setting.Value);
            }

            for (var i = 0; i < 10; i++)
            {
                if (!client.PumpEvents())
                {
                    client.WaitForEvents(500);
                }
            }

            client.Shutdown(false);
        }
示例#2
0
 public void Run()
 {
     Console.CancelKeyPress += this.ConsoleOnCancelKeyPress;
     while (!this.exitRequested)
     {
         Console.WriteLine("Attempting to connect to the server...");
         this.clientTransport = new SocketClientTransport("localhost", 3100);
         try
         {
             this.channel = this.clientTransport.Connect();
             this.SendMessages();
             this.channel.Close();
         }
         catch (SocketException)
         {
         }
     }
 }
示例#3
0
        private void Run()
        {
            this.log.Info("Application started.");
            Console.WriteLine("Application started.");
            this.isRunning = true;

            Console.CancelKeyPress += this.ConsoleOnCancelKeyPress;

            var transport = new SocketClientTransport("localhost", 3101);

            RpcClient client = null;

            while (this.isRunning)
            {
                try
                {
                    var succeeded = true;
                    this.log.Info("Connecting...");
                    client = new RpcClient(transport);

                    this.log.Info("Connected. Sending messages...");
                    var pingPong = new PingPongProxy(client);

                    for (var i = 0; i < 10000; i++)
                    {
                        try
                        {
                            var result = pingPong.Ping(i);
                            Console.Write("{0}.{1}          \r", i, result);
                        }
                        catch (RpcException ex)
                        {
                            succeeded = false;
                            if (ex.RpcStatus == RpcStatus.ChannelFailure)
                            {
                                this.log.Error("Connection lost.");
                                break;
                            }
                        }
                    }

                    if (succeeded)
                    {
                        this.log.Info("All messages sent. Shutting down...");
                        this.isRunning = false;
                    }
                    else
                    {
                        this.log.Info("Shutting down and retrying after an error.");
                    }

                    client?.Shutdown(false);
                    client = null;
                }
                catch (SocketException ex)
                {
                    if (ex.SocketErrorCode == SocketError.ConnectionRefused)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }
                }
            }

            Console.WriteLine("Application exited.");
            this.log.Info("Application exited.");
        }