Comments (13)
Try to ignore such TcpMessages, maybe it's failure of network.
from tlsharp.
@sochix yes i tried to ignore and continute but it happen again and again, and one thing is strange that sometime sequence
is valid, take a look at results i'm receiving:
first response:
avaliableBytes: 256
packageLength:1076
seq: 0 => which is correct
// failed
second response:
avaliableBytes: 1608
packageLength:1891970753
seq: 1992984927
// failed
third response:
avaliableBytes: 6644
packageLength: 6644
seq: 2 => correct
// edit: this was a correct response
forth response:
avaliableBytes: 36860
packageLength:30916
seq: 3 => correct
// this was a correct response `HandleRpcResult`
availableBytes 100
packagetLength: 100
seq: 33
// this was a correct response
availableBytes 4380
packagetLength: 37588
seq: 34
// failed
from tlsharp.
@sochix i found something, a response can be send in several tcp messages,
i get this response:
first availableBytes: 2920
packetLength: 3188
second availableBytes: 268
packetLength : -332744926
// which 2920 + 268 = 3188
i think it's because i use layer40, and telegram has not documention for it yet
from tlsharp.
@sochix changing receive to below solve the problem:
var stream = _tcpClient.GetStream();
var packetLengthBytes = new byte[4];
await stream.ReadAsync(packetLengthBytes, 0, 4);
int packetLength = BitConverter.ToInt32(packetLengthBytes, 0);
var seqBytes = new byte[4];
await stream.ReadAsync(seqBytes, 0, 4);
int seq = BitConverter.ToInt32(seqBytes, 0);
int readBytes = 0;
var body = new byte[packetLength - 12];
int neededToRead = packetLength - 12;
do
{
var bodyByte = new byte[packetLength - 12];
var availableBytes = await stream.ReadAsync(bodyByte, 0, neededToRead);
neededToRead -= availableBytes;
Buffer.BlockCopy(bodyByte, 0, body, readBytes, availableBytes);
readBytes += availableBytes;
}
while (readBytes != packetLength - 12);
var crcBytes = new byte[4];
await stream.ReadAsync(crcBytes, 0, 4);
int checksum = BitConverter.ToInt32(crcBytes, 0);
byte[] rv = new byte[packetLengthBytes.Length + seqBytes.Length + body.Length];
Buffer.BlockCopy(packetLengthBytes, 0, rv, 0, packetLengthBytes.Length);
Buffer.BlockCopy(seqBytes, 0, rv, packetLengthBytes.Length, seqBytes.Length);
Buffer.BlockCopy(body, 0, rv, packetLengthBytes.Length + seqBytes.Length, body.Length);
var crc32 = new Ionic.Crc.CRC32();
crc32.SlurpBlock(rv, 0, rv.Length);
var validChecksum = crc32.Crc32Result;
if (checksum != validChecksum)
{
throw new InvalidOperationException("invalid checksum! skip");
}
return new TcpMessage(seq, body);
from tlsharp.
Can you please, make a pull request?
from tlsharp.
@sochix of course, is the code approved by your standards? any changes?
from tlsharp.
seems to be ok =) Thank you!
from tlsharp.
where do i have to copy that code?
from tlsharp.
@siml173 at https://github.com/sochix/TLSharp/blob/master/TLSharp.Core/Network/MtProtoSender.cs#L131
replace _transport.Receieve() with it.
i'm sorry i will send the PR asap
from tlsharp.
PR created
from tlsharp.
@ra0o0f merged. Thanks!
from tlsharp.
Hi to all,
I have the same problem : "couldn't read the packet length"
From the first use of my application, I can register my phone account. After this I can send one message successfully from my application. But from the second message I get this error.
I'm using the telegram server 149.154.167.50 I changed it to several other ip adresses, but the result was the same error.
Then I tried the solution from "ra0o0f" from x-mas 2015 (see above), but then I get an arithmetic error at "var body = new byte[packetLength - 12];"
So I think, that the length of the received packet is less than 4 bytes.
Does anyone solved this problem or can help me please !?!?!?
Thanx and best wishes,
Matthias
from tlsharp.
After last update I start receiving this error very often (every about 2 minutes in my telegram client). Couldn't replicate and understand conditions because it appears randomly, but seems still actual problem.
from tlsharp.
Related Issues (20)
- Where does the library receive updates?
- How cloud I answer the inline button send by bot HOT 1
- how to get current user whene use Session
- How do I schedule a channel message to be sent (Add to Schedule List)?
- how to use TLRequestGetFullUser ? error {"USER_ID_INVALID"}
- How I can keep login after close my windows app? HOT 1
- System.InvalidOperationException: 'USER_BOT' HOT 1
- Search members in group by member's name
- How do I create a new Channel? HOT 4
- Getting an error when calling SearchUserAsync HOT 1
- How to read mesages from telegram to receive code login
- LIMIT_INVALID
- ession problem
- Session problem
- Push notifications example
- Read messages from user chat (not channel)
- Is this project being maintained? HOT 1
- How to Use TorSharp and TLsharp together
- How can I send a message to a Number that is NOT in my contacts? HOT 1
- How to edit the image of a group? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tlsharp.