sochix / TLSharp

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

An existing connection was forcibly closed by the remote host #755

Open dahuomao opened 6 years ago

dahuomao commented 6 years ago

var client = new TelegramClient(221656, "****f476224016", store, "session");

await client.ConnectAsync();

then error, "An existing connection was forcibly closed by the remote host"

this method:client.ConnectAsync();

please help me.

dahuomao commented 6 years ago

server is : 149.154.167.50:443

dahuomao commented 6 years ago

class is : Authenticator.cs
and this line: await sender.Send(step1.ToBytes());

knocte commented 6 years ago

do you get this 100% of the time? if not, maybe you need a retry mechanism in your code

dahuomao commented 6 years ago

this error is Always happen,Never succeeded

knocte commented 6 years ago

Please post the whole exception (ex.ToString()).

dahuomao commented 6 years ago

chinese is "无法将数据写入传输连接: 远程主机强迫关闭了一个现有的连接。。"

dahuomao commented 6 years ago

translation is follow: Cannot write data to transport connection: Remote host forcibly closed an existing connection.

knocte commented 6 years ago

I said exception object (which includes stacktrace), not exception message.

dahuomao commented 6 years ago
   在 System.Net.Sockets.NetworkStream.BeginWrite(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
   在 System.IO.Stream.<>c.<BeginEndWriteAsync>b__53_0(Stream stream, ReadWriteParameters args, AsyncCallback callback, Object state)
   在 System.Threading.Tasks.TaskFactory`1.FromAsyncTrim[TInstance,TArgs](TInstance thisRef, TArgs args, Func`5 beginMethod, Func`3 endMethod)
   在 System.IO.Stream.BeginEndWriteAsync(Byte[] buffer, Int32 offset, Int32 count)
   在 System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
   在 System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
   在 TLSharp.Core.Network.TcpTransport.<Send>d__3.MoveNext() 位置 D:\Work\TLSharp-master\TLSharp.Core\Network\TcpTransport.cs:行号 36
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   在 TLSharp.Core.Network.MtProtoPlainSender.<Send>d__6.MoveNext() 位置 D:\Work\TLSharp-master\TLSharp.Core\Network\MtProtoPlainSender.cs:行号 34
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   在 TLSharp.Core.Auth.Authenticator.<DoAuthentication>d__0.MoveNext() 位置 D:\Work\TLSharp-master\TLSharp.Core\Auth\Authenticator.cs:行号 13
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   在 TLSharp.Core.TelegramClient.<ConnectAsync>d__9.MoveNext() 位置 D:\Work\TLSharp-master\TLSharp.Core\TelegramClient.cs:行号 57
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   在 TLSharp.Tests.MainForm.<button1_Click>d__3.MoveNext() 位置 D:\Work\TLSharp-master\TLSharp.Tests\MainForm.cs:行号 40
dahuomao commented 6 years ago

123

legend2k commented 6 years ago

@dahuomao,have u fix this?I got the same problem.

dahuomao commented 6 years ago

@legend2k 请用一台可以直接连接电报服务器的电脑。

legend2k commented 6 years ago

@dahuomao 是不是需要国外的服务器,我在本地ping 149.154.167.50 和 telnet 149.154.167.50 443都能通。没有使用任何VPN。

dahuomao commented 6 years ago

@legend2k 是的,需要国外服务器,本地我也可以ping通,但是就是连不上,全局翻墙也不行,找了半天,最后直接在国外服务器上跑通了。

legend2k commented 6 years ago

@dahuomao 多谢多谢

dahuomao commented 6 years ago

@legend2k 找到本地翻墙可以解决的办法了联系我记得。

xiukun commented 5 years ago

@dahuomao 本地翻墙如何连接 能告知吗? qq:411560201 能加我吗 谢谢