socks5.Socks5Client.Socks5Client.Connect C# (CSharp) Method

Connect() public method

public Connect ( ) : bool
return bool
        public bool Connect()
        {
            try
            {
                p = new Socket(AddressFamily.InterNetwork, 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) {
                        Client.onDataReceived += Client_onDataReceived;
                        return true;
                    }
                return false;
            }
            catch
            {
                return false;
            }
        }

Usage Example

Example #1
0
 public override socks5.TCP.Client OnConnectOverride(socks5.Socks.SocksRequest sr)
 {
     //use a socks5client to connect to it and passthru the data.
     //port 9050 is where torsocks is running (linux & windows)
     Socks5Client s = new Socks5Client ("localhost", 9050, sr.Address, sr.Port, "un", "pw");
     if (s.Connect ()) {
         //connect synchronously to block the thread.
         return s.Client;
     } else {
         Console.WriteLine ("Failed!");
         return null;
     }
 }