From many tutorials, I get follow knowledge(maybe I'm misunderstood) :
maximum of an Ethernet packet is about 1500 bytes.
maximum of an IP packet is about 65535 bytes.
maximum of a UDP packet is 65515 bytes
But when I made a test and watch Wireshark, I get a different answer.
- I try to send some big data with TCP protocol.
Socket con = new Socket("localhost", 8088);
OutputStream os = con.getOutputStream();
StringBuilder s = new StringBuilder();
for( int i = 0; i < 10000; i++) {
s.append("Hello world");
}
// about 110k bytes
byte[] data = s.toString().getBytes();
os.write(data);
os.close();
con.close();
This is my Java code (it's not necessary to understand this.), I try to send 110k bytes data with a TCP connection. This is my Wireshark.
My 110k bytes message is split to 7 packets, I think this shows that maximum length of a TCP packet is 16388 bytes.
- Then, I try to send a UDP packet:
DatagramSocket client = new DatagramSocket(50555);
StringBuilder s = new StringBuilder();
for( int i = 0; i < 10000; i++) {
s.append("Hello world");
}
// 110k bytes
byte[] data = s.toString().getBytes();
int messageLength = data.length;
for (; ; messageLength--){
try{
DatagramPacket packet = new DatagramPacket(data, messageLength,
new InetSocketAddress("localhost", 8088));
// If packet is still too lang, above line will throws an exception
// If there is not any exception, means we can send this packet
// and this messageLength is the limit value for a UDP packet.
client.send(packet);
System.out.println("message length is " + messageLength);
// break for loop
break;
} catch(Exception e){
// fail to send and continue for loop
}
}
client.close();
the result ismessage length is 65507
.
I was really confused:
IP protocol build on Ethernet or something, Why an IP packet can be 65535 bytes when Ethernet can only send 1500 bytes?
Why an TCP packet is only 16388 bytes?
Then I have read many post on SOF or other websites, But I don't get an answer, I think is not duplicate to others.