private void onConnected(IAsyncResult res) { Client = (Client)res.AsyncState; try { Client.Sock.EndConnect(res); } catch (SocketException ex) { this.OnConnected(this, new Socks5ClientArgs(null, SocksError.Failure)); return; } if (Socks.DoSocksAuth(this, Username, Password)) { SocksError p = Socks.SendRequest(Client, enc, Dest, Destport); Client.onDataReceived += Client_onDataReceived; this.OnConnected(this, new Socks5ClientArgs(this, p)); } else { this.OnConnected(this, new Socks5ClientArgs(this, SocksError.Failure)); } }
public bool Connect() { try { p = new Socket(SocketType.Stream, ProtocolType.Tcp); Client = new Client(p, 65535); Client.Sock.Connect(new IPEndPoint(ipAddress, Port)); //try the greeting. //Client.onDataReceived += Client_onDataReceived; if (Socks.DoSocksAuth(this, Username, Password)) { if (Socks.SendRequest(Client, enc, Dest, Destport) == SocksError.Granted) { return(true); } } return(false); } catch { return(false); } }