コード例 #1
0
ファイル: Program.cs プロジェクト: Reen/protobuf-remote
        static void Main(string[] args)
        {
            Int32 port = 13000;
            IPAddress localAddr = IPAddress.Parse("127.0.0.1");

            TcpListener tcpListener = new TcpListener(localAddr, port);
            tcpListener.Start();

            while (true)
            {
                Console.WriteLine("Waiting for a connection...");

                TcpClient tcpClient = tcpListener.AcceptTcpClient();

                Console.WriteLine("Connected!");

                var controller = new RpcController();
                var server = new RpcServer(controller);

                server.RegisterService<ISampleService>(new SampleService());

                var channel = new NetworkStreamRpcChannel(controller, tcpClient.GetStream());
                channel.Start();

                while (tcpClient.Connected)
                    System.Threading.Thread.Sleep(1000);

                channel.CloseAndJoin();

                Console.WriteLine("Connection closed.\n");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Reen/protobuf-remote
        static void Main(string[] args)
        {
            Int32 port = 13000;
            TcpClient tcpClient = new TcpClient("127.0.0.1", port);

            var controller = new RpcController();
            var client = new RpcClient(controller);

            var channel = new NetworkStreamRpcChannel(controller, tcpClient.GetStream());
            channel.Start();

            ISampleService service = client.GetProxy<ISampleService>();

            int counter = 0;
            while (true)
            {
                Console.WriteLine("Enter number to test:");
                int x = Int32.Parse(Console.ReadLine());

                bool isPrime;
                if (counter++ % 2 == 0)
                {
                    Console.WriteLine(" Asking server if " + x + " is prime...");
                    isPrime = service.TestPrime(x);
                }
                else
                {
                    Console.WriteLine(" Asking server if " + x + " is prime, using an async query...");
                    IAsyncResult asyncResult = service.BeginTestPrime(x, null, null);
                    Console.WriteLine(" Doing some other stuff while the server is calculating...");
                    isPrime = service.EndTestPrime(asyncResult);
                }

                if (isPrime)
                    Console.WriteLine(" Server says: Prime!");
                else
                    Console.WriteLine(" Server says: Not prime!");
            }
        }