I assume that you are interested in how to "assemble" the packets as they are received. I have a number of clients that receive large (up to 18520 bytes) UDTs. This is how I do it.
All of the variables referenced by the form's DataArrival sub are global to preserve the data until all of it has been received. The key variable is the Integer copyPtr. It is first initialized to zero and then incremented (indirectly) by the number of bytes received. It is used as a sort of pointer for all of the CopyMemory calls needed to assemble the record.
One other thing I should point out: we use a standard 52 byte header on all of our record structures. The header contains a variety of information. Among these, the first 4 bytes is a Long that contains the size of the record (header + data). In addition, the first 2 bytes of the data is a Integer that identifies the record type. With the length, I assemble the packets until the entire record has been received. Then, with the record type, I call the appropriate handler.
VB Code:
Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
' determine the data type and process it
' get the buffer contents
ReDim gbIOBuff(bytesTotal)
tcpClient.GetData gbIOBuff, vbArray + vbByte, bytesTotal
If copyPtr = 0 Then ' we are at the beginning of a new reply
' save size & type of reply
CopyMemory recLen, gbIOBuff(0), 4
recLen = ntohl(recLen)
CopyMemory codeCheck, gbIOBuff(52), 2
codeCheck = ntohs(codeCheck)
ReDim gbReplyBuff(bytesTotal) ' clear old data record & start new one
Else
ReDim Preserve gbReplyBuff(copyPtr + bytesTotal) ' retain data & bump the size
End If
' copy the received data to the work buffer at location referenced by copyptr
CopyMemory gbReplyBuff(copyPtr), gbIOBuff(0), bytesTotal
If UBound(gbReplyBuff) = recLen Then
' we got the entire record
If recLen = gilocLen Or recLen = gijobLen Or recLen = giSockRtn Then
If codeCheck = glLocRequest Then
Process_Locations ' 1 time only at Form_Load
Else
If codeCheck = glJobRequest Then
Process_JobStats
Else
Beep
sbStatus.Panels(2).Text = "Error: " & codeCheck & ", No text returned"
intTics = 0 ' reset display timer
End If
End If
End If
copyPtr = 0 ' reset the flag\pointer
Else
' save the current record length\next copy location
copyPtr = UBound(gbReplyBuff)
End If
End Sub
HTH