Exception when reconnect to DC "An address incompatible with the requested protocol was used"
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
I have this issue too. Please help us.
@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 Can you give me your change please :) i will buy a coffee for you if you live in Sai Gon
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
Many thanks 👍 it work for me. I think you can close this issue.
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?
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);
Thank huyvu. It works
Can anyone send me updated DLL file. I cannot run
Can anyone send me updated DLL file. Please....
@kunalelearn @opranda please send me an email to [email protected] then I can reply you with updated DLL
@huyvu88 I sent you an email, please check for it. Thank you very much
@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]
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 asvar dc = dcOptions.First(d => d.Id == dcId && !d.Ipv6);
Why is this not included in official Nuget release?
Created PR to apply this fix.
Fixed by 3224113e4ce827319c049f44ee5a759ad1591fa0 using the TcpClient constructor that is not IPv4-only.