示例#1
0
 public virtual void  pushAliveReqForRecipients()
 {
     if (this.messageCoder != null)
     {
         lock (aliveRequestCheckList)
         {
             MessageEnvelope envelope = new MessageEnvelope();
             MessageBody     body     = new MessageBody();
             AliveRequest    req      = new AliveRequest();
             envelope.Id   = ("-PING-");
             req.Timestamp = (System.DateTime.Now.Ticks);
             body.selectAliveRequest(req);
             envelope.Body = (body);
             ByteBuffer buffer;
             try
             {
                 buffer = messageCoder.encode(envelope);
                 foreach (Transport transport in aliveRequestCheckList)
                 {
                     pushPacket(transport, buffer);
                 }
             }
             catch (System.Exception e)
             {
                 Console.WriteLine(e.ToString());
             }
         }
     }
 }
示例#2
0
        protected override void BeginConversation()
        {
            AliveRequest request = new AliveRequest();
            Envelope     toSend  = new Envelope(Destination, request);

            SendMessage(toSend);
        }
        public override Task <AliveResponse> Alive(AliveRequest request, ServerCallContext context)
        {
            var result = _indexService.Alive();

            return(Task.FromResult(new AliveResponse {
                Alive = result
            }));
        }
示例#4
0
        protected override void BeginConversation()
        {
            AliveRequest request = new AliveRequest();

            request.InitMessageAndConversationNumbers();
            Envelope toSend = new Envelope(Destination, request);

            WaitingForReply = true;
            SendMessage(toSend);
        }
        public void SendAndReceiveMultiple()
        {
            int           testerPort        = 45558;
            int           comServicePort    = 45556;
            string        testerAddress     = "127.0.0.1";
            string        comServiceAddress = "127.0.0.1";
            TestUdpSocket testerSocket      = new TestUdpSocket(testerPort);
            UdpTransport  testComService    = new UdpTransport();

            testComService.LocalEndpoint = new IPEndPoint(IPAddress.Any, comServicePort);

            testerSocket.Start();
            testComService.Start();
            AliveRequest request  = new AliveRequest();
            LoginRequest request2 = new LoginRequest();
            AliveReply   reply    = new AliveReply();


            int retries = 20;

            while (!(testerSocket.IsActive() && testComService.IsActive) && retries-- > 0 && wait(50))
            {
            }

            Assert.IsNotNull(testComService);
            Assert.IsTrue(testComService.IsActive);
            Assert.IsTrue(testerSocket.IsActive());

            testComService.Send(new Envelope(new IPEndPoint(IPAddress.Parse(testerAddress), testerPort), request));
            testComService.Send(new Envelope(new IPEndPoint(IPAddress.Parse(testerAddress), testerPort), reply));
            testComService.Send(new Envelope(new IPEndPoint(IPAddress.Parse(testerAddress), testerPort), request2));
            retries = 20;
            while (!testerSocket.ReplyWaiting && retries-- > 0 && wait(50))
            {
            }

            Assert.IsTrue(testerSocket.ReplyWaiting);
            Assert.IsTrue(testerSocket.Receive(out Envelope requestEnvelope));
            Assert.IsNotNull(requestEnvelope);
            Assert.IsTrue(requestEnvelope.Message.GetType() == request.GetType());
            Assert.IsTrue(requestEnvelope.Message.MsgId == request.MsgId);
            Assert.IsTrue(requestEnvelope.Message.ConvId == request.ConvId);
            Assert.IsTrue(requestEnvelope.Address.Address.ToString() == comServiceAddress);
            Assert.IsTrue(requestEnvelope.Address.Port == comServicePort);
            requestEnvelope = null;

            Assert.IsTrue(testerSocket.Receive(out requestEnvelope));
            Assert.IsNotNull(requestEnvelope);
            Assert.IsTrue(requestEnvelope.Message.GetType() == reply.GetType());
            Assert.IsTrue(requestEnvelope.Message.MsgId == reply.MsgId);
            Assert.IsTrue(requestEnvelope.Message.ConvId == reply.ConvId);
            Assert.IsTrue(requestEnvelope.Address.Address.ToString() == comServiceAddress);
            Assert.IsTrue(requestEnvelope.Address.Port == comServicePort);
            requestEnvelope = null;

            Assert.IsTrue(testerSocket.Receive(out requestEnvelope));
            Assert.IsNotNull(requestEnvelope);
            Assert.IsTrue(requestEnvelope.Message.GetType() == request2.GetType());
            Assert.IsTrue(requestEnvelope.Message.MsgId == request2.MsgId);
            Assert.IsTrue(requestEnvelope.Message.ConvId == request2.ConvId);
            Assert.IsTrue(requestEnvelope.Address.Address.ToString() == comServiceAddress);
            Assert.IsTrue(requestEnvelope.Address.Port == comServicePort);

            testerSocket.Send(new Envelope(new IPEndPoint(IPAddress.Parse(comServiceAddress), comServicePort), reply));

            retries = 20;
            while (!testComService.ReplyWaiting && retries-- > 0 && wait(50))
            {
            }

            Assert.IsTrue(testComService.ReplyWaiting);
            Assert.IsTrue(testComService.Receive(out Envelope replyEnvelope));
            Assert.IsNotNull(replyEnvelope);
            Assert.IsTrue(replyEnvelope.Message.GetType() == reply.GetType());
            Assert.IsTrue(replyEnvelope.Message.MsgId == reply.MsgId);
            Assert.IsTrue(replyEnvelope.Message.ConvId == reply.ConvId);
            Assert.IsTrue(replyEnvelope.Address.Address.ToString() == testerAddress);
            Assert.IsTrue(replyEnvelope.Address.Port == testerPort);
            testerSocket.Stop();
            testComService.Stop();

            retries = 20;
            while ((testerSocket.IsActive() || testComService.IsActive) && retries-- > 0 && wait(50))
            {
            }

            Assert.IsFalse(testComService.IsActive);
            Assert.IsFalse(testerSocket.IsActive());
        }
示例#6
0
 public void Receive(AliveRequest request)
 {
     logger.Debug("Received Alive Request");
     Reply reply = new Reply()
     {
         Success = true,
         Note = "I'm alive!"
     };
     logger.Debug("Sending Alive Reply");
     Messager.Send(reply, RegistryEndPoint);
 }
示例#7
0
        public void TcpSendReceiveValid()
        {
            IPEndPoint endpoint1 = new IPEndPoint(IPAddress.Loopback, 15655);
            IPEndPoint endpoint2 = new IPEndPoint(IPAddress.Loopback, 15651);

            TcpStreamer tcpStreamer1 = new TcpStreamer("Client");
            TcpStreamer tcpStreamer2 = new TcpStreamer("Server");

            Assert.IsNotNull(tcpStreamer1);
            Assert.IsFalse(tcpStreamer1.IsActive);
            Assert.IsFalse(tcpStreamer1.ReplyWaiting);
            Assert.IsFalse(tcpStreamer1.Connected);

            Assert.IsNotNull(tcpStreamer2);
            Assert.IsFalse(tcpStreamer2.IsActive);
            Assert.IsFalse(tcpStreamer2.ReplyWaiting);
            Assert.IsFalse(tcpStreamer2.Connected);

            tcpStreamer2.StartAsServer(endpoint1);
            Thread.Sleep(1000);
            tcpStreamer1.StartAsClient(endpoint1);
            Thread.Sleep(1000);

            Assert.IsTrue(tcpStreamer2.IsActive);
            Assert.IsFalse(tcpStreamer2.ReplyWaiting);
            Assert.IsTrue(tcpStreamer2.Connected);

            Assert.IsTrue(tcpStreamer1.IsActive);
            Assert.IsFalse(tcpStreamer1.ReplyWaiting);
            Assert.IsTrue(tcpStreamer1.Connected);


            AliveRequest request  = new AliveRequest();
            LoginRequest request2 = new LoginRequest();
            AliveReply   reply    = new AliveReply();

            tcpStreamer1.Send(new Envelope(endpoint1, request));
            tcpStreamer1.Send(new Envelope(endpoint1, reply));
            tcpStreamer1.Send(new Envelope(endpoint1, request2));

            int retries = 20;

            while (!(tcpStreamer1.ReplyWaiting || tcpStreamer2.ReplyWaiting) && retries-- > 0 && wait(50))
            {
            }

            Assert.IsTrue(tcpStreamer2.ReplyWaiting);
            Assert.IsTrue(tcpStreamer2.Receive(out Envelope requestEnvelope));
            Assert.IsNotNull(requestEnvelope);
            Assert.IsTrue(requestEnvelope.Message.GetType() == request.GetType());
            Assert.IsTrue(requestEnvelope.Message.MsgId == request.MsgId);
            Assert.IsTrue(requestEnvelope.Message.ConvId == request.ConvId);
            requestEnvelope = null;

            retries = 20;
            while (!(tcpStreamer1.ReplyWaiting || tcpStreamer2.ReplyWaiting) && retries-- > 0 && wait(50))
            {
            }

            Assert.IsTrue(tcpStreamer2.Receive(out requestEnvelope));
            Assert.IsNotNull(requestEnvelope);
            Assert.IsTrue(requestEnvelope.Message.GetType() == reply.GetType());
            Assert.IsTrue(requestEnvelope.Message.MsgId == reply.MsgId);
            Assert.IsTrue(requestEnvelope.Message.ConvId == reply.ConvId);
            requestEnvelope = null;

            retries = 20;
            while (!(tcpStreamer1.ReplyWaiting || tcpStreamer2.ReplyWaiting) && retries-- > 0 && wait(50))
            {
            }

            Assert.IsTrue(tcpStreamer2.Receive(out requestEnvelope));
            Assert.IsNotNull(requestEnvelope);
            Assert.IsTrue(requestEnvelope.Message.GetType() == request2.GetType());
            Assert.IsTrue(requestEnvelope.Message.MsgId == request2.MsgId);
            Assert.IsTrue(requestEnvelope.Message.ConvId == request2.ConvId);

            tcpStreamer2.Send(new Envelope(endpoint2, reply));

            retries = 20;
            while (!(tcpStreamer1.ReplyWaiting || tcpStreamer2.ReplyWaiting) && retries-- > 0 && wait(50))
            {
            }

            Assert.IsTrue(tcpStreamer1.ReplyWaiting);
            Assert.IsTrue(tcpStreamer1.Receive(out Envelope replyEnvelope));
            Assert.IsNotNull(replyEnvelope);
            Assert.IsTrue(replyEnvelope.Message.GetType() == reply.GetType());
            Assert.IsTrue(replyEnvelope.Message.MsgId == reply.MsgId);
            Assert.IsTrue(replyEnvelope.Message.ConvId == reply.ConvId);

            tcpStreamer2.Stop();
            tcpStreamer1.Stop();

            Thread.Sleep(1500);

            Assert.IsFalse(tcpStreamer2.IsActive);
            Assert.IsFalse(tcpStreamer2.ReplyWaiting);
            Assert.IsFalse(tcpStreamer2.Connected);

            Assert.IsFalse(tcpStreamer1.IsActive);
            Assert.IsFalse(tcpStreamer1.ReplyWaiting);
            Assert.IsFalse(tcpStreamer1.Connected);
        }