Esempio n. 1
0
        private void createConnection()
        {
            string scheme = uri.Scheme;
              string host = uri.DnsSafeHost;
              int port = uri.Port;

              if (port <= 0)
              {
            if (scheme == "wss")
            {
              port = 443;
            }
            else
            {
              port = 80;
            }
              }

              this.tcpClient = new TcpClient(host, port);
              this.netStream = tcpClient.GetStream();

              if (scheme == "wss")
              {
            this.sslStream = new SslStream(netStream);
            sslStream.AuthenticateAsClient(host);
            this.wsStream = new WsStream<SslStream>(sslStream);
              }
              else
              {
            this.wsStream = new WsStream<NetworkStream>(netStream);
              }
        }
Esempio n. 2
0
        private void close(WsState state)
        {
            #if DEBUG
              Console.WriteLine("WS: Info @close: Current thread IsBackground: {0}", Thread.CurrentThread.IsBackground);
            #endif
              if (readyState == WsState.CLOSING ||
              readyState == WsState.CLOSED)
              {
            return;
              }

              readyState = state;

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

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

              if (OnClose != null)
              {
            OnClose(this, EventArgs.Empty);
              }
            #if DEBUG
              Console.WriteLine("WS: Info @close: Exit close method.");
            #endif
        }