/// Called when an incoming message is received
        public override void MessageReceived(NetClientBase client_in, BaseMessage msg_in)
        {
            Console.WriteLine($"App: Received: from {client_in.GetNicePeerAddr()} '{msg_in.ToString()}'");
            switch (msg_in.GetType())
            {
            case MessageType.Handshake:
            {
                HandshakeMessage hsMsg = msg_in as HandshakeMessage;
                //cout << "Handshake message received, '" << hsMsg.getMyAddr() << "'" << endl;
                if (hsMsg.GetMyVersion() != "V01")
                {
                    Console.Error.WriteLine($"Wrong version '{hsMsg.GetMyVersion()}'");
                    client_in.Close();
                    return;
                }
                HandshakeResponseMessage resp = new HandshakeResponseMessage("V01", myName, client_in.GetPeerAddr());
                client_in.SendMessage(resp);
            }
            break;

            case MessageType.Ping:
            {
                PingMessage pingMsg = msg_in as PingMessage;
                //cout << "Ping message received, '" << pingMsg.GetText() << "'" << endl;
                PingResponseMessage resp = new PingResponseMessage("Resp_from_" + myName + "_to_" + pingMsg.GetText());
                client_in.SendMessage(resp);
            }
            break;

            default:
                System.Diagnostics.Debug.Assert(false);
                break;
            }
        }
Exemple #2
0
        internal void PingRequestHandler([NotNull] PingRequestMessage message)
        {
            var reply = new PingResponseMessage
            {
                ServiceName = m_Name,
                Request     = message.Request
            };

            Bus.PublishAsync(reply);
        }
        public void Setup()
        {
            m_Request = new DateTime(2011,
                                     1,
                                     1);

            m_Message = new PingResponseMessage
            {
                ServiceName = "TestService",
                Request     = m_Request,
                Response    = DateTime.Now
            };
        }
Exemple #4
0
        internal override MqttMessage Decode(byte[] message)
        {
            PingResponseMessage ping = new PingResponseMessage();
            int  index       = 0;
            byte fixedHeader = message[index];

            DecodeFixedHeader(fixedHeader);

            int remainingLength = DecodeRemainingLength(message);

            if (remainingLength != 0)
            {
            }

            return(ping);
        }
Exemple #5
0
        /// <summary>
        /// Procesa un mensaje recibido de la red
        /// </summary>
        /// <param name="message">El mensaje recibido</param>
        public void proccessMessage(Message message)
        {
            switch (message.Type)
            {
            case SubProtocol.Ping.Types.PINGMESSAGE:
            {
                PingMessage         pingMessage         = (PingMessage)message;
                PingResponseMessage pingResponseMessage = new PingResponseMessage(pingMessage.Timestamp, message.SenderNetUser);
                sendMessageEvent(pingResponseMessage);
                break;
            }

            case SubProtocol.Ping.Types.PINGRESPONSEMESSAGE:
            {
                PingResponseMessage pingResponseMessage = (PingResponseMessage)message;
                controlPingHandler.pingResponseMessageReceived(pingResponseMessage.SenderNetUser, (new TimeSpan(DateTime.Now.Ticks - pingResponseMessage.Timestamp)).TotalMilliseconds);
                break;
            }
            }
        }