private static Ping getPingMessage(NetMessage message)
        {
            NetPing netPing = message.Action.PingMessage;

            Ping ping = new Ping();

            ping.Action_id = netPing.ActionId;

            return(ping);
        }
        /// <summary>
        /// Send a Ping message to determine agent liveness.
        /// </summary>
        /// <returns>A Pong message or null if conection failed.</returns>
        public NetPong Ping()
        {
            if (IsClosed())
            {
                return(null);
            }

            NetPong localNetPong = null;

            string    actionId = Guid.NewGuid().ToString();
            NetPing   ping     = new NetPing(actionId);
            NetAction action   = new NetAction(NetAction.ActionType.PING);

            action.PingMessage = ping;
            NetMessage netMessage = new NetMessage(action);

            ManualResetEvent mrEvent = new ManualResetEvent(false);

            PongHandler handler = delegate(NetPong pong)
            {
                if (pong.ActionId.Equals(actionId))
                {
                    localNetPong = pong;
                    mrEvent.Set();
                }
            };

            protocolHandler.OnPong += handler;

            protocolHandler.HandleOutgoingMessage(netMessage, null);

            mrEvent.WaitOne(2 * 1000, false);
            protocolHandler.OnPong -= handler;

            return(localNetPong);
        }
Esempio n. 3
0
        /// <summary>
        /// Send a Ping message to determine agent liveness.
        /// </summary>
        /// <returns>A Pong message or null if conection failed.</returns>
        public NetPong Ping()
        {
            if (IsClosed())
                return null;

            NetPong localNetPong = null;

            string actionId = Guid.NewGuid().ToString();
            NetPing ping = new NetPing(actionId);
            NetAction action = new NetAction(NetAction.ActionType.PING);
            action.PingMessage = ping;
            NetMessage netMessage = new NetMessage(action);

            ManualResetEvent mrEvent = new ManualResetEvent(false);

            PongHandler handler = delegate(NetPong pong)
            {
                if (pong.ActionId.Equals(actionId))
                {
                    localNetPong = pong;
                    mrEvent.Set();
                }
            };
            protocolHandler.OnPong += handler;

            protocolHandler.HandleOutgoingMessage(netMessage, null);

            mrEvent.WaitOne(2 * 1000, false);
            protocolHandler.OnPong -= handler;

            return localNetPong;
        }