Ejemplo n.º 1
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);
        }
        private static NetPong getPongMessage(Atom atom)
        {
            NetPong pong = new NetPong(atom.Action.Pong.Action_id);

            return(pong);
        }
 private static NetPong getPongMessage(Atom atom)
 {
     NetPong pong = new NetPong(atom.Action.Pong.Action_id);
     return pong;
 }