/DotNet/Samples/PrimeClient/Program.cs

https://code.google.com/p/protobuf-remote/ · C# · 52 lines · 45 code · 7 blank · 0 comment · 4 complexity · 53bad967911c44f1f738b83d924a253c MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net.Sockets;
  5. using System.Text;
  6. using ProtoBufRemote;
  7. namespace PrimeClient
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. Int32 port = 13000;
  14. TcpClient tcpClient = new TcpClient("127.0.0.1", port);
  15. var controller = new RpcController();
  16. var client = new RpcClient(controller);
  17. var channel = new NetworkStreamRpcChannel(controller, tcpClient.GetStream());
  18. channel.Start();
  19. ISampleService service = client.GetProxy<ISampleService>();
  20. int counter = 0;
  21. while (true)
  22. {
  23. Console.WriteLine("Enter number to test:");
  24. int x = Int32.Parse(Console.ReadLine());
  25. bool isPrime;
  26. if (counter++ % 2 == 0)
  27. {
  28. Console.WriteLine(" Asking server if " + x + " is prime...");
  29. isPrime = service.TestPrime(x);
  30. }
  31. else
  32. {
  33. Console.WriteLine(" Asking server if " + x + " is prime, using an async query...");
  34. IAsyncResult asyncResult = service.BeginTestPrime(x, null, null);
  35. Console.WriteLine(" Doing some other stuff while the server is calculating...");
  36. isPrime = service.EndTestPrime(asyncResult);
  37. }
  38. if (isPrime)
  39. Console.WriteLine(" Server says: Prime!");
  40. else
  41. Console.WriteLine(" Server says: Not prime!");
  42. }
  43. }
  44. }
  45. }