sochix / TLSharp

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

SocketException when initializing TelegramClient #837

Open StaticDDQ opened 5 years ago

StaticDDQ commented 5 years ago

Hi, when I tried running the code initially, I always get a SocketException when initializing the client. I've inputted the correct hash and id but I keep getting the error, "No connection could be made because the target machine actively refused it".

I tried turning off firewall and it still doesn't help.

ghost commented 4 years ago

I have the same error. Does anybody know how to solve this issue?

knocte commented 4 years ago

Please paste whole exception (ex.ToString()).

ghost commented 4 years ago

"System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 149.154.167.51:443\r\n at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)\r\n at System.Net.Sockets.TcpClient.Connect(IPEndPoint remoteEP)\r\n at TLSharp.Core.Network.TcpTransport..ctor(String address, Int32 port, TcpClientConnectionHandler handler)\r\n at TLSharp.Core.TelegramClient..ctor(Int32 apiId, String apiHash, ISessionStore store, String sessionUserId, TcpClientConnectionHandler handler)\r\n at BusinessLogicLayer.CTelegramLoader..ctor() in C:\Users\...\CTelegramLoader.cs:line 36"

knocte commented 4 years ago

@CloneDeath any suggestion? ^ not IPv6 related but...

CloneDeath commented 4 years ago

Either Telegram, or someone between you and them, are refusing the connection. Not an issue with the software, but rather with your network (most likely).

Are you connected to a VPN? Are you behind a corporate firewall? Do you know your router's security policies? If you're in AWS or gcloud, I'd check the whole pipeline for any security issues...

If you're behind a corporate firewall, and you can run the SW on a dev machine, then maybe try running it on another network (like starbucks, a home network, or, maybe tether it to your phone). If it works in one of those networks, then it's definitely the corporate firewall, and you're going to have to work with IT or w/e to figure it out.

AI-Inaan commented 4 years ago

Same Error here

            new TelegramClient(apiid, apihash);
            await client.ConnectAsync();
            hash = await client.SendCodeRequestAsync(number);

System.Net.Sockets.SocketException: 'A socket operation was attempted to an unreachable network [2001:b28:f23f:f005::a]:443'

System.Net.Sockets.Socket.DoConnect(System.Net.EndPoint, System.Net.SocketAddress)
    System.Net.Sockets.Socket.Connect(System.Net.EndPoint)
    System.Net.Sockets.TcpClient.Connect(System.Net.IPEndPoint)
    TLSharp.Core.Network.TcpTransport.TcpTransport(string, int, TLSharp.Core.Network.TcpClientConnectionHandler)
    TLSharp.Core.TelegramClient.ReconnectToDcAsync(int)
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    System.Runtime.CompilerServices.TaskAwaiter.GetResult()
    TLSharp.Core.TelegramClient.RequestWithDcMigration(TeleSharp.TL.TLMethod)
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
shreeraj04 commented 4 years ago

Same issue here. Has anyone got any solutions for this ?

knocte commented 4 years ago

@shreeraj04 your stacktrace contains an IPv6 address? If yes, or just @InThU, you could try this PR: https://github.com/sochix/TLSharp/pull/858

shreeraj04 commented 4 years ago

@knocte My stacktrace doesn't contain an IPv6 addr. I changed my configuration to test IP after this I don't see this issue. But now I get "Phone_Number_Unoccupied" message. I logged out from Telegram in phone but still I get same Phone_Number_Unoccupied message. Any idea ?

shreeraj04 commented 4 years ago

This I solved using registering my number in test configuration IP. But now I am sending a message to one registered number, but the person is not receiving the message.

AI-Inaan commented 4 years ago

@shreeraj04 your stacktrace contains an IPv6 address? If yes, or just @InThU, you could try this PR: #858

i will try it out thanks for the suggestion