Beispiel #1
0
 private static void DemoRequestReplyWithSingleClientContext(string connectAddress, string bindAddress)
 {
     Console.WriteLine("\r\nPattern Request/Reply (multiple requesters with single context factory):");
     using (var clientFactory = new Client.RequestClientFactory())
         using (var client1 = clientFactory.Create(connectAddress))
             using (var client2 = clientFactory.Create(connectAddress))
                 using (var client3 = clientFactory.Create(connectAddress))
                     using (var server = new Server.ReplyReceiver(bindAddress))
                     {
                         var clients = new IRequestClient[]
                         {
                             client1,
                             client2,
                             client3
                         };
                         for (int i = 0; i < clients.Length; i++)
                         {
                             var client     = clients[i];
                             var clientName = string.Format("Client{0}", i + 1);
                             Task.Factory.StartNew(() =>
                             {
                                 for (int j = 0; j < 3; j++)
                                 {
                                     var response = client.Send(new RequestMsg(string.Format("#{0} {1}, what are you doing !?", j, clientName)));
                                     Console.WriteLine("{1} response: {0}", response, clientName);
                                 }
                             });
                         }
                         server.Start();
                         Thread.Sleep(1000);
                     }
 }
Beispiel #2
0
 private static void DemoRequestReply(string connectAddress, string bindAddress)
 {
     Console.WriteLine("\r\nPattern Request/Reply:");
     using (var client = new Client.RequestClient(connectAddress))
         using (var server = new Server.ReplyReceiver(bindAddress))
         {
             server.Start();
             for (int i = 0; i < 3; i++)
             {
                 var response = client.Send(new RequestMsg(string.Format("#{0} What are you doing !?", i)));
                 Console.WriteLine("Response: {0}", response);
             }
             Thread.Sleep(1000);
         }
 }