sochix / TLSharp

Telegram client library implemented in C#
1k stars 380 forks source link

Working with proxy #880

Closed str1py closed 5 years ago

str1py commented 5 years ago

Im trying use proxy in TLSharp like im saw in previous essues.

So, what i have done

   TcpClient TcpHandler(string address, int port)
        {
            var proxy = Properties.Settings.Default.ProxyInUse.Split(';');
            Socks5ProxyClient proxyClient = new Socks5ProxyClient(proxy[0].Trim(), Int32.Parse(proxy[1]));
            TcpClient client = proxyClient.CreateConnection(address, port);
            return client;
        }

and then

client = new TelegramClient(Properties.Settings.Default.TelegramApiID, Properties.Settings.Default.TelegramApiHash, store, "session", handler: TcpHandler);

But every time with any proxy (socks, http) I have exeption

proxy error: the connection was refuced by the remote network for destination host 149.154.175.100 port number 443. Server response (hex); 05050000000000......

Im trying starksoft-aspen and starksoftproxy

What am I do wrong?

xsharov commented 5 years ago

@str1py I have same problem. How did you solve this?

str1py commented 5 years ago

@str1py I have same problem. How did you solve this?

Socks5 have unstable behavior in C# because the same proxy work, and then when i`m try to connect one more time to the same Socks5 it doesnt work. Although proxies are working. I checked in telegram. I desided to use HTTP proxy instead Socks5. Use it like this

 HttpProxyClient webProxyClient;
//proxy 1-ip 2-port 3-login 4-pass
                if (proxy[3] == "")
                    webProxyClient = new HttpProxyClient(proxy[1], Int32.Parse(proxy[2]));
                else
                    webProxyClient = new HttpProxyClient(proxy[1], Int32.Parse(proxy[2]), proxy[3], proxy[4]);

                try
                {
                    TcpClient client = webProxyClient.CreateConnection(address, port);
                    return client;
                }
                catch
                {
                    return null;
                }

But before use selected proxy i Ping it and do test connection to telegram.

vuminhit commented 4 years ago

@str1py

I try HttpProxyClient at https://github.com/meebey/starksoftproxy but not found HttpProxyClient support proxy with username and password.

Can you share with me your HttpProxyClient class support proxy with username and password