public void Open() { this._parser = new StreamParser(); this._parser.OnStreamStart += this.OnStreamStart; this._parser.OnStreamElement += this.OnStreamElement; this._parser.OnStreamEnd += this.OnStreamEnd; this._parser.OnStreamError += this.OnStreamError; this._parser.OnError += this.OnStreamError; var data = new byte[short.MaxValue]; this._stream.BeginRead(data, 0, data.Length, ReadCallback, data); this.OnOpen?.Invoke(this); }
public void Close() { if (this._closed) { return; } this._closed = true; this._log.Debug("close."); this.Send("</stream:stream>"); this._can_read = false; this._can_write = false; if (this._stream != null) { this._stream.Dispose(); this._stream = null; } if (this._client != null) { this._client.Dispose(); this._client = null; } if (this._parser != null) { this._parser.OnStreamStart -= this.OnStreamStart; this._parser.OnStreamElement -= this.OnStreamElement; this._parser.OnStreamEnd -= this.OnStreamEnd; this._parser.OnStreamError -= this.OnStreamError; this._parser.OnError -= this.OnStreamError; this._parser = null; } OnClose?.Invoke(this); if (this.Session != null) { this.Session.Dispose(); this.Session = null; } }