sochix / TLSharp

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

The requested address is not valid in its context #862

Closed WatchDogsDev closed 5 years ago

WatchDogsDev commented 5 years ago

Hello , When I start the new version and try to connect , It throws "the requested address is not valid in its context" socket exception. This issue has appeared since version 0.1.0.390

My code :

 var Client = new TelegramClient(API_ID, API_HASH);
                await Client.ConnectAsync();
                await Task.Delay(250);
                sHash = await Client.SendCodeRequestAsync(number);
overw1ite commented 5 years ago

same problem

alishokr commented 5 years ago

@WatchDogsDev @overw1ite

I had the same issue. i fixed it by making changes to TcpTransport constructor.

public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null)
        {
            if (handler == null)
            {
                /*var ipAddress = IPAddress.Parse(address);
                var endpoint = new IPEndPoint(ipAddress, port);*/

                _tcpClient = new TcpClient();
                _tcpClient.Connect(address,port);
            }
            else
                _tcpClient = handler(address, port);
        }
knocte commented 5 years ago

@alishokr if you do that you're basically reverting the last commit which in theory added support for IPv6. We need a better fix that detects if the IP address is IPv4 or IPv6, and use a different constructor of TcpClient() class depending on that.

alishokr commented 5 years ago

@alishokr if you do that you're basically reverting the last commit which in theory added support for IPv6. We need a better fix that detects if the IP address is IPv4 or IPv6, and use a different constructor of TcpClient() class depending on that.

you're right. i needed quick fix.

emreordukaya commented 5 years ago

You can see this post #859

knocte commented 5 years ago

Fixed in 00330c9bd010945285e56027345d3f37bcf4792a