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,

CodePudding user response:

reference 4 floor Tiger_Zhao 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,

Such a garbage answer can't stand it

CodePudding user response:


DATAARRAVAL eventP1=d0 (18) * 500 'd0 (18) is 19 bytes in baotou, its value is now 40 bags which one of the bags
For I=0 to 499
D (p1 + I)=d0 (24 + I * 2) * 256 + d0 (24 + I * 2 + 1) 'a point two bytes, 40 package of baotou, total is 40000 bytes, a total of 20000 points in a d () array inside

Now the question is, if accept DATAARRAVAL event began to accept is not from the first package, but from 40 accept 20th in the package, then d () stored in the array is 10000 points before the next cycle before sending 40 in 20 packets, and then after the 10000 points is the current cycle of 40, so how to determine the forty package is 40 a loop inside the bag

CodePudding user response:

Because you have design flaws in the structure of data, so there is no solution, in front of the reference solution

CodePudding user response:

Look not to understand is not wrong,
The correct method when the garbage is people have a problem!

CodePudding user response:

 'is a byte array, a total of 40000 bytes, sent via UDP protocol, divided into 40 package, each package to 1000 bytes, 
'before each packet with 24 bytes of baotou, namely each bag contains 1024 bytes, 18 bytes are fixed in front of baotou
'fixed invariable, the 19th byte represents a single set of total number off, this also is fixed, is 40;
20 bytes is said'the location of this package is 40 in which one (0.. Four bytes of 39), behind is the systemic circulation said, says is sent is the first
'a few 40000 bytes, or understandable to send which one 40 package, because the 40 package is a collection of data, determine the
'after this 40 bag inside an array

'global variables
Dim Pack as Byte (0 to 1023)
Dim Data as Byte (0 to 39999)
Dim Received (0 to 39) as Boolean
Dim as Long L
Dim as Long I

'receiving treatment:
WinSock1. GetData Pack, vbArray + vbByte, 1024
L=Clng (Pack (19)) mod 40
The Debug. Print "received the first" + CStr (L) + "package"
Received (L)=True
L=L * 1000
For I=0 to 999
Data (L + I)=Pack (24 + I)
Next
For I=0 to 39
If not Received (I) then the exit for
Next
If i> 39 then
The Debug. Print "all 40 package has been received and in the Data array"
Endif

CodePudding user response:


'global variables
Dim Pack as Byte (0 to 1023)
Dim Data as Byte (0 to 39999)
Dim Received (0 to 39) as Boolean
Dim as Long L
Dim as Long I

'receiving treatment:
WinSock1. GetData Pack, vbArray + vbByte, 1024
L=Clng (Pack (19)) mod 40
The Debug. Print "received the first" + CStr (L) + "package"
Received (L)=True
L=L * 1000
For I=0 to 999
Data (L + I)=Pack (24 + I)
Next
For I=0 to 39
If not Received (I) then the exit for
Next
If i> 39 then
The Debug. Print "all 40 package has been received and in the Data array"
Endif
[/code]



If accepted, starts from the 20th package that what to do, at this point in the Data array Data is in front of a cycle of 40, 20 before the package at the back of the Data is the current cycle after 20 packets of Data

CodePudding user response:

With structure strength more flexibility to deal with this problem, otherwise, need to use a two-dimensional array, you go to optimize the code, thinking is others, code must be your own?
And one of the biggest problems already and you said, you don't have the different batches of data interference processing, grasp the key problem, want to do first

CodePudding user response:

 'is a byte array, a total of 40000 bytes, sent via UDP protocol, divided into 40 package, each package to 1000 bytes, 
'before each packet with 24 bytes of baotou, namely each bag contains 1024 bytes, 18 bytes are fixed in front of baotou
'fixed invariable, the 19th byte represents a single set of total number off, this also is fixed, is 40;
20 bytes is said'the location of this package is 40 in which one (0.. Four bytes of 39), behind is the systemic circulation said, says is sent is the first
'a few 40000 bytes, or understandable to send which one 40 package, because the 40 package is a collection of data, determine the
'after this 40 bag inside an array

'global variables
Const MAXN as long=1000 'most closed MAXN a
Dim Pack as Byte (0 to 1023)
Dim Data (0, 0 to 39999) to MAXN - 1 as Byte
Dim Received (0, 0 to MAXN - 1 to 39) as Boolean
Dim P As Long
Dim as Long L
Dim as Long I

'receiving treatment:
WinSock1. GetData Pack, vbArray + vbByte, 1024
L=Clng (Pack (19)) mod 40
P=(1 & amp; * Pack (20) + 256 & amp; * Pack (21) + 65536 & amp; * Pack (22) + 16777216 & amp; * Pack (23)) mod MAXN 'high after the low byte first byte is stored
nullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related