Networks are used to transmit data over the world. There is a lot of network protocols in use. But most known and used protocols are IP,TCP,UDP. IP lives different flat but TCP and UDP tries to live same flat. So they operate same network layer but what is different between UDP and TCP. Why should I use TCP or not use? Same questions can be asked for UDP too. In this post, we will look what is the same and different for these protocols. TCP stands for Transmission Control Protocol. UDP stands for User Datagram Protocol
OSI Network Layer
They both live the same Layer according to OSI Reference Model. We call this layer as Transmission Layer. In this layer between sockets, data is transmitted. They have no difference in this side.
UDP have lean package structure. UDP provides just Source, Destination Port, Length, Checksum in its header part.
TCP has more field in the package because TCP transmission has more steps and controls for package delivery. TCP has 12 header field.
TCP is absolutely more complex than UDP protocol. As we see in the upper side TCP have a lot of area for transmission related mechanisms. For example, TCP provides windows mechanism which sets transmission buffer related memory.
UDP has just checksum mechanism and packet counter which is sometimes not implemented.
To transmit data with TCP a session must be created with a method named 3-way handshake. The first client sends a packet with SYN flag is set and the server responds with ACK flags and the last step the client sends SYNC+ACK to accomplish a TCP session with the related server.
UDP does not have any special algorithm. UDP packages are directly sent to the server’s port. Management did generally in the upper application layer.
The complexity of TCP protocol makes TCP slower than UDP. At least to send just a single byte there need to be a session initialization and after data transfer close the session. This makes TCP slower. There is some work done about the speed of TCP but the architecture is limited new enhancements.
UDP is lightfast if you transmit it over fiber optic 😉 .UDP is fast because there are no algorithms for session or session termination.
TCP is a reliable protocol because it runs mechanisms to prevent data loss or change. TCP uses sessions to make data transmission reliability. Also in the data transfer, transmitted data is checked by between sides and if some loss or change occurred data is re-transmitted again.
UDP is nor reliable. Really it is not. But if you want it to be reliable upper layer application level mechanisms can be implemented but these will make the transmission more complex.
From the security point of view, both TCP and UDP is the same. Actually, TCP has some little advantages because of its session management but for a general look, there are both secure if security mechanisms like SSL, Encryption is implemented. Implementing SSL/TLS like protocols for TCP is very easy besides UDP. On the other side, voice communication protocol like RTP can be upgraded to the SRTP to make underlying UDP more secure.
In this part we will list protocols using UDP or TCP or both.
Following protocols are using UDP transmission.
Following protocols are using TCP transmission.