예제 #1
0
 private static void HandleRpcEvent(RpcTestEvent message, PingPongClient client)
 {
     lock (pingPongLock)
     {
         eventResult = message.id + "";
         Monitor.Pulse(pingPongLock);
     }
 }
예제 #2
0
        public void PingPong()
        {
            var server = new PingPongServer();
            var client = new PingPongClient(new Client(server.LocalEndPoint));
            var aEvent = new RpcTestEvent();

            aEvent.id = 922;
            var message = new RpcTestRequest();

            message.id = 316;
            client.OutgoingService.SendRequest(message, typeof(RpcTestResponse),
                                               delegate(ProtoBuf.IExtensible response)
            {
                var responseMessage = (RpcTestResponse)response;
                lock (pingPongLock)
                {
                    clientResult = responseMessage.id + "";
                    Monitor.Pulse(pingPongLock);
                }
            },
                                               delegate(ProtoBuf.IExtensible fail)
            {
                lock (pingPongLock)
                {
                    clientResult = "wrong!";
                    if (fail is RpcTestException)
                    {
                    }
                    ;
                    Monitor.Pulse(pingPongLock);
                }
            });
            lock (pingPongLock)
            {
                while (server.serverSession == null)
                {
                    Monitor.Wait(pingPongLock);
                }
            }
            server.serverSession.OutgoingService.PushMessage(aEvent);
            lock (pingPongLock)
            {
                while (serverResult == null || clientResult == null || eventResult == null)
                {
                    Monitor.Wait(pingPongLock);
                }
            }
            Assert.AreEqual(clientResult, "710");
            Assert.AreEqual(serverResult, "316");
            Assert.AreEqual(eventResult, "922");
            client.Session.ShutDown();
            server.serverSession.Session.ShutDown();
            server.Clear();
        }
예제 #3
0
        public static void Main(String[] args)
        {
            //Default is to PingPong between client and server twice
            int ticks = (args.Length == 0) ? 10 : Convert.ToInt32(args[0]);
            //Create a PingPong client
            PingPongClient pingPongClient = new PingPongClient(new InstanceContext(new PingPongCallback()));
            pingPongClient.Open();
            pingPongClient.Ping(ticks);
            pingPongClient.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
예제 #4
0
        public static void Main(String[] args)
        {
            //Default is to PingPong between client and server twice
            int ticks = (args.Length == 0) ? 10 : Convert.ToInt32(args[0]);
            //Create a PingPong client
            PingPongClient pingPongClient = new PingPongClient(new InstanceContext(new PingPongCallback()));

            pingPongClient.Open();
            pingPongClient.Ping(ticks);
            pingPongClient.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }