TLSharp icon indicating copy to clipboard operation
TLSharp copied to clipboard

Exception when reconnect to DC "An address incompatible with the requested protocol was used"

Open huyvu88 opened this issue 8 years ago • 16 comments

I got this error message when TLSharp try to reconnect to DC once DataCenterMigrationException appears: "An address incompatible with the requested protocol was used [2001:b28:f23f:f005::a]:443"

Take a look at https://github.com/sochix/TLSharp/blob/master/TLSharp.Core/TelegramClient.cs - RequestWithDcMigration() catch block.

I google this error and found out it should be the mismatch between IpV6 and IpV4 which lead me to https://github.com/sochix/TLSharp/blob/master/TLSharp.Core/Network/TcpTransport.cs ` public TcpTransport(string address, int port, TcpClientConnectionHandler handler = null) { if (handler == null) { _tcpClient = new TcpClient();

            var ipAddress = IPAddress.Parse(address);
            _tcpClient.Connect(ipAddress, port);
        }
        else
            _tcpClient = handler(address, port);
    }

` I believed that some returned DC which uses IpV6 that cause this error, please help to fix it

huyvu88 avatar Jun 04 '18 09:06 huyvu88

I have this issue too. Please help us.

ctphu avatar Jun 09 '18 15:06 ctphu

@ctphu I have a workaround while waiting @sochix have time to take a look. datacenter options (dcOptions variable) returned in ConnectAsync() method has a couple of ipv6 ver and ipv4 ver (example: dc's id 5 could has 2 public ip (one is ipv6 and the other is ipv4), you can modify the TLSharp code that get the DC by dc's id to get ipv4 only then it worked, i tried,

huyvu88 avatar Jun 09 '18 16:06 huyvu88

@huyvu88 Can you give me your change please :) i will buy a coffee for you if you live in Sai Gon

ctphu avatar Jun 09 '18 16:06 ctphu

find this line of code in TelegramClient.cs, you're welcome. I live in Hanoi ... ship me a coffee if it worked to you LOL

huyvu88 avatar Jun 09 '18 16:06 huyvu88

Many thanks 👍 it work for me. I think you can close this issue.

ctphu avatar Jun 09 '18 16:06 ctphu

I'm reopening the issue because no one has merged a fix in TLSharp. @huyvu88 can you provide your fix in a diff/PR form instead of a screenshot please?

knocte avatar Jun 10 '18 10:06 knocte

Hi @knocte, this could be a workaround - find this line of code in TelegramClient.cs var dc = dcOptions.First(d => d.Id == dcId); Modify it as var dc = dcOptions.First(d => d.Id == dcId && !d.Ipv6);

huyvu88 avatar Jun 12 '18 03:06 huyvu88

Thank huyvu. It works

huynhfxvn avatar Jun 20 '18 15:06 huynhfxvn

Can anyone send me updated DLL file. I cannot run

kunalelearn avatar Jul 02 '18 10:07 kunalelearn

Can anyone send me updated DLL file. Please....

HelpWithWritingAnEssay avatar Aug 09 '18 11:08 HelpWithWritingAnEssay

@kunalelearn @opranda please send me an email to [email protected] then I can reply you with updated DLL

huyvu88 avatar Aug 09 '18 14:08 huyvu88

@huyvu88 I sent you an email, please check for it. Thank you very much

hrtlkr29 avatar Sep 25 '18 09:09 hrtlkr29

@huyvu88 I sent you an email, please check for it. Thank you very much

Please,can you send the updated dll to this id [email protected]

ajaycse2109 avatar Dec 05 '18 06:12 ajaycse2109

Hi @knocte, this could be a workaround - find this line of code in TelegramClient.cs var dc = dcOptions.First(d => d.Id == dcId); Modify it as var dc = dcOptions.First(d => d.Id == dcId && !d.Ipv6);

Why is this not included in official Nuget release?

paramhq avatar Feb 14 '19 07:02 paramhq

Created PR to apply this fix.

CloneDeath avatar Jun 19 '19 16:06 CloneDeath

Fixed by 3224113e4ce827319c049f44ee5a759ad1591fa0 using the TcpClient constructor that is not IPv4-only.

knocte avatar Jun 28 '19 05:06 knocte