Home > Software engineering > Help: vb how to judge the UDP packet in baotou, and according to the information contained in the ba
Help: vb how to judge the UDP packet in baotou, and according to the information contained in the ba
Time:10-03
A byte array, a total of 40000 bytes, sent via UDP protocol, divided into 40 package, each package to 1000 bytes, each package before plus 24 bytes of baotou, namely each bag contains 1024 bytes, baotou in front of 18 bytes are fixed, the 19th is the total number off of a single set of bytes, this also is fixed, is 40. 20 bytes is said the location of this package is 40 which one in the package, the back of the systemic circulation of four bytes is said, is what was sent to 40000 bytes, or understandable to send which one 40 package, because the 40 package is a collection of data, after the judgment to the 40 bag inside an array, thank you!
CodePudding user response:
Said the "header" is not appropriate, and udp packets of baotou ambiguous, you can call it the data portion of the head, to handle is not very tedious, you can consult: Add the definition type: datPak, members of the index (int) for this package in this group of data of id, PakCount (int) on behalf of this group of data to the total number of packages, databyte () on behalf of the truncated data, the head of this group of data According to the first package, the total number of packages for the group, set the length of datPak array, and then read the packet id filling into the corresponding datPak After each package also read package id and fill in the corresponding datPak Finish with a for loop,
Don't know how your contract frequency, there are 40000 bytes are sent, or every other period of time to send a 40000, if the former, different batches of package will interfere with each other, also need to adjust the package structure, set for this batch of 40000 - byte packets a batch number (e.g., generated time), in order to distinguish between; If it's over time will send a 40000 - byte, it doesn't matter, there will be no interference,
CodePudding user response:
About the frequency of the contract is, in other words is the time to accept may not accept from the first package, but from other packages to accept, this time is about to throw away the bags, directly from the next cycle, can you give an example reference, I probably know what you mean, but do not know how to start,
CodePudding user response:
Order does not need to discard packets, otherwise don't have to cut 40000 bytes of data, directly will do, Don't get all packages, only need to discard packets, if conditions permit, it is best to adjust the package for data definition, take the data batch, where did you just say you have a problem
CodePudding user response:
UDP package if can be disorderly, So you subcontract information should be put on these information: Bundle ID, avoid mixing multiple sets of data, Total length, received the first package can be used to create an array of data, The subcontract, received the first package can be used to create a Boolean array, Subcontract, Boolean array subscript to mark which package has been received, Actually index, is the data of the array subscript, used to fill to the starting position of the array, Data length,
Check the Boolean array after each packet processing, all received can output data array,