예제 #1
0
        public TcpXmppConnection(IXmppListener listener, TcpClient client)
        {
            this._listener = listener;
            this._client   = client;
            this._stream   = this._client.GetStream();

            var id = Guid.NewGuid().ToString("D");

            this.Session = new TcpXmppSession(id);
            this._log    = LogManager.GetLogger($"{GetType().Name}/{id}");
        }
예제 #2
0
        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;
            }
        }