Reputation: 6784
I am examining packets captured using Wireshark.
I understand the value of the Total Length field in the IP datagram (packet) is the total size of the datagram which includes size of header and data. The size of header is fixed 40 bytes (20 bytes for encapsulated TCP header + 20 bytes for IP header). However in each of my packets I noticed the size of data is variable ranging from 1 byte to the range of ~ 1500 bytes.
My Java application is sends messages wrapped with a header \x0b and a trailer \x0c\x0d. So my message sending format is:
0b Message 0c0d
However if I examine the sent packets in Wireshark, I can see that some packets only contain 0b in the data. Some packets contain 0b + part of message.
I am curious to know why the data part of the packet is variable.
Upvotes: 0
Views: 3142
Reputation: 689
Is your code sending the bytes to the networking layer atomically or in pieces? If in pieces, sometimes the networking stack will have the nagle algorithm turned on to try and coalesce multiple short TCP payloads into one large payload, but this is not guaranteed to happen. And as TCP is a stream protocol, there so no guarantee the number of TCP packets will be equal to number of times TCP send is called. Also it is up to your receiving code to properly segment the TCP input stream along message boundaries.
Upvotes: 1