简体   繁体   中英

How does Java form TCP packets from byte arrays?

While SocketIn/OutputStreams in Java seem stream based to an API user, TCP packets are packet based. One can write only one byte or an array of bytes. But one could also write more bytes than a TCP packet could carry.

So how does Java form TCP packets from the write methods?

Creates calling write(singleByte) 4 times 4 TCP packets? Or does java join the bytes together?

Does java join and split bytes to form the TCP packets?

No, Java, or more precisely the Java Virtual Machine, has no reason to get into these details.

What the JVM does, is that it opens a native Socket just like any native program would. It then allows the Java code to interact with the native socket through the various Java API. This leaves the networking details to the operating system's network stack (TCP/IP implementation).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM