TCP stream vs UDP message

后端 未结 6 810
悲哀的现实
悲哀的现实 2020-11-29 01:45

TCP is stream oriented meaning data is transferred as a continues stream of bytes. But what confuses me is that TCP creates segments and passes this down to IP. IP creates p

6条回答
  •  醉话见心
    2020-11-29 01:57

    TCP is stream oriented because it is able to assemble data in contiguous format. E.g. you had data from number 1 to 4000 bytes. Now it will be divided into tcp segments where each segment would have a sequence number say first is 1-1200 byte, second is 1201 - 2400 and so on.

    It might be delivered out of order while being sent through ip datagrams but is assembled into contiguous data latter, thereby appearing as a stream. The sequence number helps to reorder packets.

    A little deeper explanation is:

    A byte stream consist of one big chunk of data with no segments or other irregularities. With datagrams (smaller) data chunks are send and received at once as a whole. In practice it means that with datagrams each send/write call sends one packet, and each read/recv call receives one packet, while with stream protocol the data can be send and received in any way. E.g. A sender can call send() ten times, while the receiver receives all that data with one recv call. With datagrams ten send calls means ten packets and ten receive calls

    Datagrams and streams

    Byte streams

提交回复
热议问题