private void StartConnect() { try { CreateRemote(); // TODO async resolving IPAddress ipAddress; bool parsed = IPAddress.TryParse(server.server, out ipAddress); if (!parsed) { IPHostEntry ipHostInfo = Dns.GetHostEntry(server.server); ipAddress = ipHostInfo.AddressList[0]; } IPEndPoint destEP = new IPEndPoint(ipAddress, server.server_port); // Setting up proxy IPEndPoint proxyEP; if (_config.useProxy) { parsed = IPAddress.TryParse(_config.proxyServer, out ipAddress); if (!parsed) { IPHostEntry ipHostInfo = Dns.GetHostEntry(_config.proxyServer); ipAddress = ipHostInfo.AddressList[0]; } remote = new Socks5Proxy(); proxyEP = new IPEndPoint(ipAddress, _config.proxyPort); } else { remote = new DirectConnect(); proxyEP = destEP; } ProxyTimer proxyTimer = new ProxyTimer(3000); proxyTimer.AutoReset = false; proxyTimer.Elapsed += proxyConnectTimer_Elapsed; proxyTimer.Enabled = true; proxyTimer.DestEndPoint = destEP; proxyTimer.Server = server; _proxyConnected = false; // Connect to the proxy server. remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), proxyTimer); } catch (Exception e) { Logging.LogUsefulException(e); Close(); } }
private void StartConnect() { try { CreateRemote(); // Setting up proxy EndPoint proxyEP; if (_config.useProxy) { remote = new Socks5Proxy(); proxyEP = SocketUtil.GetEndPoint(_config.proxyServer, _config.proxyPort); } else { remote = new DirectConnect(); proxyEP = null; } ProxyTimer proxyTimer = new ProxyTimer(3000); proxyTimer.AutoReset = false; proxyTimer.Elapsed += proxyConnectTimer_Elapsed; proxyTimer.Enabled = true; proxyTimer.Proxy = remote; proxyTimer.DestEndPoint = SocketUtil.GetEndPoint(server.server, server.server_port); proxyTimer.Server = server; _proxyConnected = false; // Connect to the proxy server. remote.BeginConnectProxy(proxyEP, new AsyncCallback(ProxyConnectCallback), proxyTimer); } catch (Exception e) { Logging.LogUsefulException(e); Close(); } }