TCP vs UDP:
TCP and UDP are two transport protocols that work on the transport layer on the OSI model and are responsible for delivering messages between networked hosts. Also thei are respinsible for fragmentation and reassembly of the packages sent. However the similarities stop here because the two protocols have different ways in handling data and working with it.
Let’s start with TCP…. The very first thing that needs to be done before any data can be exchanged is the opennig of a “socket” and a point-to-point connection is established that provides a bidirectional data path between the partners. The TCP way of work is by using data streams instead of data blocks, so the transport mechanism will split and concatenate the blocks on the fly to reduce the overhead and it will use one IP packet for each TCP frame to facilitate the correction of lost data. In consequence TCP allows a safe connection without data loss but the bandwith consumed is larger than in UDP.
UDP is different, instead of working with data streams it works with data blocks. The size of data block can consist of maximum 64 kbytes and it is considered transferred if all IP packets that it consists are received. If one of them is lost the complete UDP block is discarded. In UDP there are no sockets there is only a port provided where any device on the net can send UDP data to. Because of the way it works UDP allows you to do broadcasting, by sending a data messages that go to all UDP receivers on the network that opened a port to receive them also it less bandwith.