sochix / TLSharp

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

Couldn't read the packet length #915

Open LitleDuck opened 4 years ago

LitleDuck commented 4 years ago

When I try to sendmessageasync to the user from my contacts I have this exception:

exception

There the code: ` static async Task MainAsync(string[] args) { var store = new FileSessionStore(); using (var client = new TelegramClient(API_KEY, "**", store, "session")) { await client.ConnectAsync();

            Console.WriteLine("OK");

                var hash = await client.SendCodeRequestAsync("380*******");

                Console.Write("Code: ");

                var code = Console.ReadLine();

                var user = await client.MakeAuthAsync("380*******", hash, code);

            if (client.IsUserAuthorized())
            {

                var dialogsResult = await client.GetContactsAsync();

                var userid = dialogsResult.Users
                .Where(x => x.GetType() == typeof(TLUser))
                .OfType<TLUser>()
                .FirstOrDefault(x => x.Username.ToLower() == "*****".ToLower());

                var message = new TLInputPeerUser { UserId = userid.Id, AccessHash = userid.AccessHash.Value };

                Thread.Sleep(1200);

               // await  client.SendMessageAsync(message, "hello world! My friend!");

                while (true)
                {
                    try
                    {
                        while ((current_line = reader.ReadLine()) != null)
                        {
                            string login = current_line.Split(':')[0].Trim();
                            string password = current_line.Split(':')[1].Trim();
                            try
                            {
                                using (ImapClient imap = new ImapClient("imap.gmail.com", 993, login, password, AuthMethod.Login, true))
                                {
                                    IEnumerable<uint> uids = imap.Search(SearchCondition.Unseen().And(SearchCondition.From("@facebookmail.com").Or(SearchCondition.From("@linkedin.com").Or(SearchCondition.From("@facebook.com")))));

                                    IEnumerable<MailMessage> messages = imap.GetMessages(uids, FetchOptions.TextOnly);

                                    foreach (MailMessage m in messages)
                                    {
                                        string message_body = "Email: " + login + Environment.NewLine + m.Body;

                                        await client.SendMessageAsync(message, message_body);
                                    }

                                }
                            }
                            catch
                            {
                                await client.SendMessageAsync(message, "Some error occured at email: " + login);
                            }

                        }
                    }
                    catch(Exception ex)
                    {
                        await client.SendMessageAsync(message, ex.Message);
                    }
                    reader.BaseStream.Seek(0, SeekOrigin.Begin);

                    Thread.Sleep(650000);
                }
            }
            else
                Console.WriteLine("No auth!");

`

knocte commented 4 years ago

@CheshireCaat what do you think?

LitleDuck commented 4 years ago

image

LitleDuck commented 4 years ago

There is exception which called after previous

CheshireCaat commented 4 years ago

@LitleDuck I noticed that you are from Russia. It seems that the problem is that Telegram is blocked in this country. Are you using proxy or VPN to connect to the Telegram using TLSharp? I sent message using the library just now (i use VPN). Everything works fine.

LitleDuck commented 4 years ago

@LitleDuck I noticed that you are from Russia. It seems that the problem is that Telegram is blocked in this country. Are you using proxy or VPN to connect to the Telegram using TLSharp? I sent message using the library just now (i use VPN). Everything works fine.

Hi, I am start my bot at Amazon Dedicated Server and this problem come out after few messages from my bot to user and I can't sent more because of this error(sorry for my bad English)

CheshireCaat commented 4 years ago

@LitleDuck, If you really need help (in this case from me), you should consider at least two points:

  1. It is necessary to provide a minimal working code example on which i can repeat this errors.
  2. Provide a complete stack trace for your exceptions.

And please, format your code normally, or put it on resources like pastebin. Do not send a stack trace with a message, better with a file or use pastebin in the same way.

LitleDuck commented 4 years ago

@LitleDuck, If you really need help (in this case from me), you should consider at least two points:

  1. It is necessary to provide a minimal working code example on which i can repeat this errors.
  2. Provide a complete stack trace for your exceptions.

And please, format your code normally, or put it on resources like pastebin. Do not send a stack trace with a message, better with a file or use pastebin in the same way.

So I can get u source code

CheshireCaat commented 4 years ago

@LitleDuck, you can send me the code to likangt2012@gmail.com

LitleDuck commented 4 years ago

The trouble was in AWS. Close