Наследование: IDisposable
Пример #1
0
 internal WebSocket(TcpListenerWebSocketContext context)
     : this()
 {
     _wsStream     = context.Stream;
     _closeContext = () => context.Close();
     init(context);
 }
Пример #2
0
        private bool closeConnection()
        {
            _readyState = WsState.CLOSED;

            try
            {
                if (!_httpContext.IsNull())
                {
                    _httpContext.Response.Close();
                    _wsStream    = null;
                    _httpContext = null;
                }

                if (!_wsStream.IsNull())
                {
                    _wsStream.Dispose();
                    _wsStream = null;
                }

                if (!_tcpClient.IsNull())
                {
                    _tcpClient.Close();
                    _tcpClient = null;
                }

                return(true);
            }
            catch (Exception ex)
            {
                onError(ex.Message);
                return(false);
            }
        }
Пример #3
0
        // As Client
        private void setClientStream()
        {
            var host = _uri.DnsSafeHost;
            var port = _uri.Port;

            _tcpClient = new TcpClient(host, port);
            _wsStream  = WsStream.CreateClientStream(_tcpClient, host, _secure);
        }
Пример #4
0
 // As Server
 private void closeResourcesAsServer()
 {
     if (!_context.IsNull() && !_closeContext.IsNull())
     {
         _closeContext();
         _wsStream = null;
         _context  = null;
     }
 }
Пример #5
0
        // As client
        private void init()
        {
            _base64key = createBase64Key();

            var host = _uri.DnsSafeHost;
            var port = _uri.Port;

            _tcpClient = new TcpClient(host, port);
            _wsStream  = WsStream.CreateClientStream(_tcpClient, host, _secure);
        }
Пример #6
0
        // As Client
        private void createClientStream()
        {
            var host = _uri.DnsSafeHost;
            var port = _uri.Port > 0
               ? _uri.Port
               : _isSecure ? 443 : 80;

            _tcpClient = new TcpClient(host, port);
            _wsStream  = WsStream.CreateClientStream(_tcpClient, host, _isSecure);
        }
Пример #7
0
 internal WebSocket(TcpListenerWebSocketContext context)
     : this()
 {
     _uri       = context.Path.ToUri();
     _context   = context;
     _tcpClient = context.Client;
     _wsStream  = context.Stream;
     _endPoint  = context.ServerEndPoint;
     _isClient  = false;
     _isSecure  = context.IsSecureConnection;
 }
Пример #8
0
 internal WebSocket(HttpListenerWebSocketContext context)
     : this()
 {
     _uri         = Ext.ToUri(context.Path);
     _context     = context;
     _httpContext = context.BaseContext;
     _wsStream    = context.Stream;
     _endPoint    = context.ServerEndPoint;
     _isClient    = false;
     _isSecure    = context.IsSecureConnection;
 }
Пример #9
0
        // As Client
        private void closeResourcesAsClient()
        {
            if (!_wsStream.IsNull())
            {
                _wsStream.Dispose();
                _wsStream = null;
            }

            if (!_tcpClient.IsNull())
            {
                _tcpClient.Close();
                _tcpClient = null;
            }
        }
Пример #10
0
        internal T ReadHandshake <T>(Func <string[], T> parser, int millisecondsTimeout) where T : HandshakeBase
        {
            bool  timeout = false;
            Timer timer   = new Timer(delegate(object state)
            {
                timeout = true;
                this._innerStream.Close();
            }, null, millisecondsTimeout, -1);
            T         result = (T)((object)null);
            Exception ex     = null;

            try
            {
                result = parser(WsStream.readHandshakeHeaders(this._innerStream));
                string text = result.Headers["Content-Length"];
                if (text != null && text.Length > 0)
                {
                    result.EntityBodyData = WsStream.readHandshakeEntityBody(this._innerStream, text);
                }
            }
            catch (Exception ex2)
            {
                ex = ex2;
            }
            finally
            {
                timer.Change(-1, -1);
                timer.Dispose();
            }
            string text2 = (!timeout) ? ((ex == null) ? null : "An exception has occurred while receiving a handshake.") : "A timeout has occurred while receiving a handshake.";

            if (text2 != null)
            {
                throw new WebSocketException(text2, ex);
            }
            return(result);
        }
Пример #11
0
        // As client
        private void closeClientResources()
        {
            if (_stream != null) {
            _stream.Dispose ();
            _stream = null;
              }

              if (_tcpClient != null) {
            _tcpClient.Close ();
            _tcpClient = null;
              }
        }
Пример #12
0
 // As server
 private void closeResourcesAsServer()
 {
     if (!_context.IsNull() && !_closeContext.IsNull()) {
         _closeContext();
         _wsStream = null;
         _context = null;
     }
 }
Пример #13
0
 // As Client
 private void setClientStream()
 {
     var host = _uri.DnsSafeHost;
       var port = _uri.Port;
       _tcpClient = new TcpClient(host, port);
       _wsStream = WsStream.CreateClientStream(_tcpClient, host, _secure);
 }
Пример #14
0
        // As Client
        private void createClientStream()
        {
            var host = _uri.DnsSafeHost;
              var port = _uri.Port;
              if (port <= 0)
            port = IsSecure ? 443 : 80;

              _wsStream = WsStream.CreateClientStream(host, port, out _tcpClient);
        }
Пример #15
0
 internal WebSocket(HttpListenerWebSocketContext context)
     : this()
 {
     _uri         = context.Path.ToUri();
       _context     = context;
       _httpContext = context.BaseContext;
       _wsStream    = context.Stream;
       _endPoint    = context.ServerEndPoint;
       _isClient    = false;
       _isSecure    = context.IsSecureConnection;
 }
Пример #16
0
        // As client
        private void closeResourcesAsClient()
        {
            if (!_wsStream.IsNull()) {
                _wsStream.Dispose();
                _wsStream = null;
            }

            if (!_tcpClient.IsNull()) {
                _tcpClient.Close();
                _tcpClient = null;
            }
        }
Пример #17
0
 // As server
 private void closeResourcesAsServer()
 {
     if (_context != null && _closeContext != null)
       {
     _closeContext();
     _wsStream = null;
     _context = null;
       }
 }
Пример #18
0
        // As server
        private void closeServerResources()
        {
            if (_closeContext == null)
            return;

              _closeContext ();
              _closeContext = null;
              _stream = null;
              _context = null;
        }
Пример #19
0
        // As client
        private bool closeClientResources()
        {
            try {
            if (_stream != null)
            {
              _stream.Dispose ();
              _stream = null;
            }

            if (_tcpClient != null)
            {
              _tcpClient.Close ();
              _tcpClient = null;
            }

            return true;
              }
              catch (Exception ex) {
            _logger.Fatal (ex.ToString ());
            error ("An exception has occurred.");

            return false;
              }
        }
Пример #20
0
 // As client
 private void setClientStream()
 {
     var host = _uri.DnsSafeHost;
       var port = _uri.Port;
       _tcpClient = new TcpClient (host, port);
       _stream = WsStream.CreateClientStream (_tcpClient, _secure, host, _certValidationCallback);
 }
Пример #21
0
 // As server
 private void closeServerResources()
 {
     if (_context != null && _closeContext != null)
       {
     _closeContext ();
     _stream = null;
     _context = null;
       }
 }
Пример #22
0
        // As Client
        private void createClientStream()
        {
            var host = _uri.DnsSafeHost;
            var port = _uri.Port > 0
                     ? _uri.Port
                     : _isSecure ? 443 : 80;

            _tcpClient = new TcpClient(host, port);
            _wsStream = WsStream.CreateClientStream(_tcpClient, host, _isSecure);
        }
Пример #23
0
        private bool closeConnection()
        {
            _readyState = WsState.CLOSED;

            try
            {
                if (_httpContext != null)
                {
                    _httpContext.Response.Close();
                    _wsStream = null;
                    _httpContext = null;
                }

                if (_wsStream != null)
                {
                    _wsStream.Dispose();
                    _wsStream = null;
                }

                if (_tcpClient != null)
                {
                    _tcpClient.Close();
                    _tcpClient = null;
                }

                return true;
            }
            catch (Exception ex)
            {
                onError(ex.Message);
                return false;
            }
        }
Пример #24
0
 internal WebSocket(TcpListenerWebSocketContext context)
     : this()
 {
     _uri = Ext.ToUri(context.Path);
     _context = context;
     _tcpClient = context.Client;
     _wsStream = context.Stream;
     _endPoint = context.ServerEndPoint;
     _isClient = false;
     _isSecure = context.IsSecureConnection;
 }
Пример #25
0
        // As server
        internal WebSocket(TcpListenerWebSocketContext context, Logger logger)
        {
            _context = context;
              _logger = logger;

              _closeContext = context.Close;
              _secure = context.IsSecureConnection;
              _stream = context.Stream;
              _uri = context.Path.ToUri ();

              init ();
        }
Пример #26
0
        // As client
        private void init()
        {
            _base64key = createBase64Key();

              var host = _uri.DnsSafeHost;
              var port = _uri.Port;
              _tcpClient = new TcpClient(host, port);
              _wsStream = WsStream.CreateClientStream(_tcpClient, host, _secure);
        }
Пример #27
0
        // As server
        private bool closeServerResources()
        {
            try {
            if (_closeContext != null)
              _closeContext ();

            _stream = null;
            _context = null;

            return true;
              }
              catch (Exception ex) {
            _logger.Fatal (ex.ToString ());
            error ("An exception has occurred.");

            return false;
              }
        }
Пример #28
0
        // As client
        private void closeResourcesAsClient()
        {
            if (_wsStream != null)
              {
            _wsStream.Dispose();
            _wsStream = null;
              }

              if (_tcpClient != null)
              {
            _tcpClient.Close();
            _tcpClient = null;
              }
        }
Пример #29
0
 internal WebSocket(TcpListenerWebSocketContext context)
     : this()
 {
     _stream = context.Stream;
       _closeContext = () => context.Close ();
       init (context);
 }
Пример #30
0
    internal const int FragmentLength = 1016; // Max value is int.MaxValue - 14.

    #endregion

    #region Internal Constructors

    // As server
    internal WebSocket (HttpListenerWebSocketContext context, Logger logger)
    {
      _context = context;
      _logger = logger;

      _closeContext = context.Close;
      _secure = context.IsSecureConnection;
      _stream = context.Stream;
      _uri = context.RequestUri;

      init ();
    }