예제 #1
0
        /// <summary>
        /// Envia el mensaje en respuesta a otro
        /// </summary>
        /// <param name="msg">Mensahe</param>
        /// <param name="inResponseTo">En respuesta a</param>
        /// <returns></returns>
        public int SendReply(IXPloitSocketMsg msg, IXPloitSocketMsg inResponseTo)
        {
            if (inResponseTo != null)
            {
                XPloitMsgHeaderId headerId = inResponseTo.Headers.GetHeader <XPloitMsgHeaderId>();
                if (headerId != null)
                {
                    msg.Headers.Add(XPloitMsgHeaderReply.CreateNew(headerId.Id));
                }
            }

            return(Send(msg));
        }
예제 #2
0
        /// <summary>
        /// Lee el mensaje o devuelve null si no hay
        /// </summary>
        public IXPloitSocketMsg Read()
        {
            if (_Stream == null)
            {
                return(null);
            }

            try
            {
                if (_Socket.Available <= 0)
                {
                    return(null);
                }

                IXPloitSocketMsg msg = _Protocol.Read(_Stream);
                _LastRead = DateTime.Now;

                if (msg == null)
                {
                    return(null);
                }
                _MsgReceived++;

                XPloitMsgHeaderReply inResponse = msg.Headers.GetHeader <XPloitMsgHeaderReply>();

                if (inResponse != null)
                {
                    if (!Guid.Equals(inResponse.InResponseTo, Guid.Empty))
                    {
                        _Actions.Add(inResponse.InResponseTo, msg);
                        return(null);
                    }
                }

                if (OnMessage != null)
                {
                    OnMessage(this, msg);
                }

                return(msg);
            }
            catch (Exception e)
            {
                Disconnect(EDissconnectReason.Error);
                return(null);
            }
        }