Ejemplo n.º 1
0
        /// <summary>
        /// Close the connection.
        /// </summary>
        public virtual void Close()
        {
            // close stream and socket
            try
            {
                if (Client.Connected)
                {
                    Stream.Close();
                    Client.Close();
                }
            }
            catch (Exception e)
            {
                HandleException(e);
            }

            // invoke event
            if (!_wasClosedEventCalled)
            {
                _eventsListener.OnConnectionClosed(this);
                _wasClosedEventCalled = true;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Close the connection.
        /// </summary>
        public virtual void Close()
        {
            // close stream and socket
            // call event earlier so disconnect event will always be able to make use of the tcpclient before its disposed
            // invoke event
            if (!_wasClosedEventCalled)
            {
                _eventsListener.OnConnectionClosed(this);
                _wasClosedEventCalled = true;
            }

            try
            {
                if (Client.Connected)
                {
                    Stream.Close();
                    Client.Close();
                }
            }
            catch (Exception e)
            {
                HandleException(e);
            }
        }