public bool Start(MeshCentralServer parent, Uri url, string user, string pass, string token, string fingerprint)
            {
                if (state != 0)
                {
                    return(false);
                }
                parent.changeState(1);
                state       = 1;
                this.parent = parent;
                this.url    = url;
                this.user   = user;
                this.pass   = pass;
                this.token  = token;
                Uri proxyUri = null;

                // Check if we need to use a HTTP proxy (Auto-proxy way)
                try {
                    RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
                    Object      x           = registryKey.GetValue("AutoConfigURL", null);
                    if ((x != null) && (x.GetType() == typeof(string)))
                    {
                        string proxyStr = GetProxyForUrlUsingPac("http" + ((url.Port == 80) ? "" : "s") + "://" + url.Host + ":" + url.Port, x.ToString());
                        if (proxyStr != null)
                        {
                            proxyUri = new Uri("http://" + proxyStr);
                        }
                    }
                } catch (Exception) { proxyUri = null; }

                // Check if we need to use a HTTP proxy (Normal way)
                if (proxyUri == null)
                {
                    var proxy = System.Net.HttpWebRequest.GetSystemWebProxy();
                    proxyUri = proxy.GetProxy(url);
                    if ((url.Host.ToLower() == proxyUri.Host.ToLower()) && (url.Port == proxyUri.Port))
                    {
                        proxyUri = null;
                    }
                }

                if (proxyUri != null)
                {
                    // Proxy in use
                    proxyInUse = true;
                    wsclient   = new TcpClient();
                    wsclient.BeginConnect(proxyUri.Host, proxyUri.Port, new AsyncCallback(OnConnectSink), this);
                }
                else
                {
                    // No proxy in use
                    proxyInUse = false;
                    wsclient   = new TcpClient();
                    wsclient.BeginConnect(url.Host, url.Port, new AsyncCallback(OnConnectSink), this);
                }
                return(true);
            }
 public void Dispose()
 {
     try { wsstream.Close(); } catch (Exception) { }
     try { wsstream.Dispose(); } catch (Exception) { }
     wsstream = null;
     wsclient = null;
     state    = -1;
     parent.changeState(0);
     parent.wshash = null;
 }