static void Main(string[] args) { IRemoteNamedPipeServer serv = new PingPongServer("PingPong"); serv.LogEvent += (sender, e) => { Console.WriteLine(e.Message); }; Console.WriteLine("Press any key to stop..."); Console.ReadKey(); }
public void pong() { Console.WriteLine("[Executando o método pong no componente Pong]"); Receptacle receptacle = context.GetReceptacles()["PongRec"]; foreach (ConnectionDescription connection in receptacle.GetConnections()) { PingPongServer pingPongServer = connection.objref as PingPongServer; pingPongServer.pong(); } }
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(); }
public void PingPong() { var server = new PingPongServer(); var client = new PingPongClint(server.LocalEndPoint); byte[] ping = new UTF8Encoding(true).GetBytes("ping"); IList <ArraySegment <byte> > sendBuffer = new List <ArraySegment <byte> >(); ArraySegment <byte> pingArraySegment = new ArraySegment <byte>(ping, 0, ping.Length); sendBuffer.Add(pingArraySegment); client.Send(sendBuffer); lock (testLock) { while (serverResult == null || clientResult == null) { Monitor.Wait(testLock); } } Assert.AreEqual(serverResult, "ping"); Assert.AreEqual(clientResult, "pong"); client.ShutDown(); server.Clear(); }
public void PingPong() { var server = new PingPongServer(); var client = new PingPongClint(server.LocalEndPoint); byte[] ping = new UTF8Encoding(true).GetBytes("ping"); IList<ArraySegment<byte>> sendBuffer = new List<ArraySegment<byte>>(); ArraySegment<byte> pingArraySegment = new ArraySegment<byte>(ping, 0, ping.Length); sendBuffer.Add(pingArraySegment); client.Send(sendBuffer); lock (testLock) { while (serverResult == null || clientResult == null) { Monitor.Wait(testLock); } } Assert.AreEqual(serverResult, "ping"); Assert.AreEqual(clientResult, "pong"); client.ShutDown(); server.Clear(); }
static void Main() { log4net.Config.XmlConfigurator.Configure(); Console.WriteLine("Pressione 'enter' quando o componente Ping estiver no ar."); Console.ReadLine(); OrbServices.CreateAndRegisterIiopChannel(0); ComponentId pongComponentId = new ComponentId("PingPong", 1, 0, 0, ""); ComponentContext pongContext = new DefaultComponentContext(pongComponentId); MarshalByRefObject pongServant = new PongServant(pongContext); string pingpongRepID = Repository.GetRepositoryID(typeof(PingPongServer)); //Criando o component Pong. pongContext.AddFacet("Pong", pingpongRepID, pongServant); pongContext.AddReceptacle("PingRec", pingpongRepID, false); String pingIorPath = Pong.Properties.Resources.IorFilename; StreamReader stream = new StreamReader(pingIorPath); String pingIor; try { pingIor = stream.ReadToEnd(); } finally { stream.Close(); } //Recuperar a faceta Ping. OrbServices orb = OrbServices.GetSingleton(); IComponent pingComponent = orb.string_to_object(pingIor) as IComponent; MarshalByRefObject pingObj = pingComponent.getFacetByName("Ping"); //Recuperar a faceta Pong. IComponent pongComponent = pongContext.GetIComponent(); MarshalByRefObject pongObj = pongComponent.getFacetByName("Pong"); //Conectar o Ping em Pong. IReceptacles pingIReceptacles = pingComponent.getFacetByName("IReceptacles") as IReceptacles; pingIReceptacles.connect("PongRec", pongObj); //Conectar o Pong em Ping. IReceptacles pongIReceptacles = pongComponent.getFacetByName("IReceptacles") as IReceptacles; pongIReceptacles.connect("PingRec", pingObj); Console.WriteLine("Executando ping e pong no Componente Ping"); PingPongServer pingServer = pingComponent.getFacet(pingpongRepID) as PingPongServer; pingServer.ping(); pingServer.pong(); Console.WriteLine("--\n"); Console.WriteLine("Executando ping e pong no Componente Pong"); PingPongServer pongServer = pongComponent.getFacet(pingpongRepID) as PingPongServer; pongServer.ping(); pongServer.pong(); Console.WriteLine("--\n"); MarshalByRefObject pingMetaInterfaceObj = pingComponent.getFacetByName("IMetaInterface"); IMetaInterface pingMetaInterface = pingMetaInterfaceObj as IMetaInterface; FacetDescription[] PingFacets = pingMetaInterface.getFacets(); foreach (var facet in PingFacets) { Console.WriteLine(facet.name + " --- " + facet.interface_name); } Console.WriteLine("Fim"); Console.ReadLine(); }