private void PushService(FPData quest) { lock (self_locker) { FPClient self = this; this._psr.Service(quest, (payload, exception) => { FPData data = new FPData(); data.SetFlag(quest.GetFlag()); data.SetMtype(0x2); data.SetSeq(quest.GetSeq()); data.SetSS(exception ? 1 : 0); if (quest.GetFlag() == 0) { data.SetPayload(Convert.ToString(payload)); } if (quest.GetFlag() == 1) { data.SetPayload((byte[])payload); } self.SendQuest(data); }); } }
private void ReadSocket(NetworkStream stream, Action <NetworkStream> calllback) { FPClient self = this; try { int len = this._buffer.Length - this._readBytes; stream.BeginRead(this._buffer, this._readBytes, len, (ar) => { try { int readBytes = stream.EndRead(ar); if (readBytes == 0) { self._sock.Close(null); } else { self._readBytes += readBytes; calllback(stream); } } catch (Exception ex) { self._sock.Close(ex); } }, null); } catch (Exception ex) { self._sock.Close(ex); } }
private void ReadSocket(NetworkStream stream, byte[] buffer, Action <NetworkStream> calllback) { FPClient self = this; try { stream.BeginRead(buffer, 0, buffer.Length, (ar) => { try { int readBytes = stream.EndRead(ar); if (readBytes == 0) { self._sock.Close(null); } else { calllback(stream); } } catch (Exception ex) { self._sock.Close(ex); } }, null); } catch (Exception ex) { self._sock.Close(ex); } }
private void ReadBytes(NetworkStream stream, FPData peek, byte[] buffer, int rlen, Action <NetworkStream, FPData, byte[]> calllback) { if (rlen < buffer.Length) { FPClient self = this; this._sock.ReadSocket(stream, buffer, rlen, (buf, len) => { self.ReadBytes(stream, peek, buf, len, calllback); }); return; } if (calllback != null) { calllback(stream, peek, buffer); } }
protected void Init(string host, int port, bool autoReconnect, int connectionTimeout) { this._pkg = new FPPackage(); this._cyr = new FPEncryptor(_pkg); this._event = new FPEvent(); this._psr = new FPProcessor(); this._callback = new FPCallback(); if (connectionTimeout > 0) { this._timeout = connectionTimeout; } this._autoReconnect = autoReconnect; FPClient self = this; this._eventDelegate = (evd) => { self.OnSecond(evd.GetTimestamp()); }; ThreadPool.Instance.Event.AddListener("second", this._eventDelegate); this._sock = new FPSocket((stream) => { self.OnData(stream); }, host, port, this._timeout); this._sock.GetEvent().AddListener("connect", (evd) => { self.OnConnect(); }); this._sock.GetEvent().AddListener("close", (evd) => { self.OnClose(); }); this._sock.GetEvent().AddListener("error", (evd) => { self.OnError(evd.GetException()); }); }