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(); } }
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); }
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); }
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); }
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); }
public bool IsTwoWay(FPData data) { return(1 == data.GetMtype()); }
public bool IsOneWay(FPData data) { return(0 == data.GetMtype()); }
public bool IsJson(FPData data) { return(0 == data.GetFlag()); }
public bool IsMsgPack(FPData data) { return(1 == data.GetFlag()); }
public bool IsTcp(FPData data) { return(BytesCompare(FPConfig.TCP_MAGIC, data.GetMagic())); }
public bool IsSupportPack(FPData data) { return(this.IsMsgPack(data) != this.IsJson(data)); }
public CallbackData SendQuest(FPData data, int timeout) { //TODO return(null); }
public void SendQuest(FPData data, CallbackDelegate callback) { this.SendQuest(data, callback, 0); }
public void SendQuest(FPData data) { this.SendQuest(data, null, 0); }
public bool IsQuest(FPData data) { return(this.IsTwoWay(data) || this.IsOneWay(data)); }
public bool IsAnswer(FPData data) { return(2 == data.GetMtype()); }
public bool IsHttp(FPData data) { return(BytesCompare_Base64(FPConfig.HTTP_MAGIC, data.GetMagic())); }
public CallbackData(FPData data) { this._data = data; }
public EventData(string type, FPData data) { this._type = type; this._data = data; }