Пример #1
0
        private void OnClose()
        {
            this._seq       = 0;
            this._readBytes = 0;
            this._peekData  = null;

            if (this._buffer != null)
            {
                Array.Clear(this._buffer, 0, this._buffer.Length);
                this._buffer = null;
            }

            this._callback.RemoveCallback();
            this._cyr.Clear();

            this._event.FireEvent(new EventData("close", !this._isClose && this._autoReconnect));

            if (this._autoReconnect)
            {
                this.Reconnect();
            }
        }
Пример #2
0
        private void BuildData(NetworkStream stream, FPData peek)
        {
            peek.Bytes = this._cry.DeCode(peek.Bytes);
            FPData data = this._cry.PeekHead(peek);

            if (!this._pkg.DeCode(data))
            {
                this._sock.Close(new Exception("worng package body!"));
                return;
            }

            if (this._pkg.IsAnswer(data))
            {
                this.ExecCallback(data);
            }

            if (this._pkg.IsQuest(data))
            {
                this.PushService(data);
            }

            this.ReadHead(stream);
        }
Пример #3
0
        private byte[] EnCodeTwoway(FPData data)
        {
            if (data != null)
            {
                System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
                MemoryStream ms = this.BuildHeader(data, 16 + data.GetSS() + data.GetPsize());
                ms.WriteByte((byte)data.GetSS());
                byte[] psizeBytes = BitConverter.GetBytes(data.GetPsize());
                ms.Write(psizeBytes, 0, psizeBytes.Length);
                byte[] seqBytes = BitConverter.GetBytes(data.GetSeq());
                ms.Write(seqBytes, 0, seqBytes.Length);
                string method      = (data.GetMethod() != null) ? data.GetMethod() : "";
                byte[] methodBytes = encoder.GetBytes(method);
                ms.Write(methodBytes, 0, methodBytes.Length);
                byte[] payloadBytes = null;

                if (this.IsJson(data))
                {
                    string json = (data.JsonPayload() != null) ? data.JsonPayload() : "";
                    payloadBytes = encoder.GetBytes(json);
                }

                if (this.IsMsgPack(data))
                {
                    payloadBytes = data.MsgpackPayload();
                }

                if (payloadBytes != null)
                {
                    ms.Write(payloadBytes, 0, payloadBytes.Length);
                }

                return(this.StreamToBytes(ms));
            }

            return(null);
        }
Пример #4
0
        public bool DeCode(FPData data)
        {
            if (data != null)
            {
                byte[] bytes = this.GetByteArrayRange(data.Bytes, 12, data.Bytes.Length - 1);

                if (this.IsOneWay(data))
                {
                    return(this.DeCodeOneWay(bytes, data));
                }

                if (this.IsTwoWay(data))
                {
                    return(this.DeCodeTwoWay(bytes, data));
                }

                if (this.IsAnswer(data))
                {
                    return(this.DeCodeAnswer(bytes, data));
                }
            }

            return(false);
        }
Пример #5
0
        private void BuildData(NetworkStream stream)
        {
            this._peekData.Bytes = this._cyr.DeCode(this._peekData.Bytes);
            this._peekData       = this._cyr.PeekHead(this._peekData);

            if (!this._pkg.DeCode(this._peekData))
            {
                this._sock.Close(new Exception("worng package body!"));
                return;
            }

            if (this._pkg.IsAnswer(this._peekData))
            {
                this.ExecCallback(this._peekData);
            }

            if (this._pkg.IsQuest(this._peekData))
            {
                this.PushService(this._peekData);
            }

            this._peekData = null;
            this.OnData(stream);
        }
Пример #6
0
 public bool IsTwoWay(FPData data)
 {
     return(1 == data.GetMtype());
 }
Пример #7
0
 public bool IsOneWay(FPData data)
 {
     return(0 == data.GetMtype());
 }
Пример #8
0
 public bool IsJson(FPData data)
 {
     return(0 == data.GetFlag());
 }
Пример #9
0
 public bool IsMsgPack(FPData data)
 {
     return(1 == data.GetFlag());
 }
Пример #10
0
 public bool IsTcp(FPData data)
 {
     return(BytesCompare(FPConfig.TCP_MAGIC, data.GetMagic()));
 }
Пример #11
0
 public bool IsSupportPack(FPData data)
 {
     return(this.IsMsgPack(data) != this.IsJson(data));
 }
Пример #12
0
 public CallbackData SendQuest(FPData data, int timeout)
 {
     //TODO
     return(null);
 }
Пример #13
0
 public void SendQuest(FPData data, CallbackDelegate callback)
 {
     this.SendQuest(data, callback, 0);
 }
Пример #14
0
 public void SendQuest(FPData data)
 {
     this.SendQuest(data, null, 0);
 }
Пример #15
0
 public bool IsQuest(FPData data)
 {
     return(this.IsTwoWay(data) || this.IsOneWay(data));
 }
Пример #16
0
 public bool IsAnswer(FPData data)
 {
     return(2 == data.GetMtype());
 }
Пример #17
0
 public bool IsHttp(FPData data)
 {
     return(BytesCompare_Base64(FPConfig.HTTP_MAGIC, data.GetMagic()));
 }
Пример #18
0
 public CallbackData(FPData data)
 {
     this._data = data;
 }
Пример #19
0
 public EventData(string type, FPData data)
 {
     this._type = type;
     this._data = data;
 }