My understanding is that TCP is considered "reliable" because the receiver acknowledges packet receipt and requests a resend if there is any problem. My file transfer program currently sends files in 32767 byte packets, though I have experimented with all sizes. Sending a 10 meg file that requires 340 packets consistently results in three or four packets on the receiver being significantly smaller than what was sent. I always end up with a file that is very slightly different from the original.
As an example, my log records the size of all packets received:
TCP packet received (32767 bytes)
TCP packet received (32767 bytes)
TCP packet received (14600 bytes)
TCP packet received (32767 bytes)
My sending thread reads the file in 32767 byte chunks and calls a sending sub:
MyFile.Read(Buffer, 0, BufferSize)
SendTCPData(Address, Buffer)
My TCP code is very simple:
Shared Sub SendTCPData(Address As String, ByVal Data As Byte())
Dim Client As New TcpClient(Address, PortNumber)
Dim Stream As NetworkStream = Client.GetStream()
Stream.Write(Data, 0, Data.Length)
Stream.Close()
Client.Close()
End Sub
Can anyone help? (The post "TCP Client to Server communication" does not deal with with how to handle received packet sizes, which is my question.)