As already mentioned, TCP is a streaming protocol. This means that from the point of view of the API there is no concept of a “package”. As a user, all you can expect is a stream of data.
Internally, TCP splits the stream into segments that can be placed in IP packets. These packets will be sent along with the control data over IP to the remote end. The remote end will receive these IP packets. It can discard specific IP packets (in the case of duplicates), reorder packets, or hold data until earlier packets arrive. All this is internal to TCP, which means that the concept of a "TCP packet" does not make sense.
You might be able to use raw sockets to receive raw IP packets, but that would mean that you would have to override most of the TCP stack (for example, send an ACK and adjust the window size) to get the remote end to work properly. You do not want to do this.
UDP, on the other hand, is a datagram protocol. This means that the user receives information about how data is transmitted over the network. If the concept of packets or datagrams is important to you, you will need to create your own protocol on top of UDP.
doron
source share