TCP and UDP are some of the most famous terms in networking, even common people come to know about it. So we have to learn more about TCP and UDP. This is our new networking blog.

As we all know, The Internet is the publicly available worldwide system of interconnected computer networks that transmit data by packet switching over the Internet Protocol (IP). So Transfering data from source to destination needs a protocol.

What is TCP ?

Transmission Control Protocol is a widely used network protocol for transferring data. So let’s go some deeper. The first thing to know when saying about TCP is, its a connection-oriented communication method. so TCP establishes a session between the host and destination before starting communication.

Initialising a TCP connection

TCP states when connecting
  • When a new TCP connection is opened, the client (initiator) sends a SYN packet to the server and updates its state to SYN-SENT.
  • The server will then send a SYN-ACK in reply to the client which changes its connection state to SYN-RECEIVED.
  • If it’s worked properly, the client will reply with an ACK and the connection is marked as ESTABLISHED on both end-point.

Now they are ready to transfer data.

Termination of a TCP connection

TCP states when terminating
  • The client sends a FIN packet to the server and updates its state to FIN-WAIT-1.
  • The server receives the termination request from the client and responds with an ACK. After the reply, the server will be in a CLOSE-WAIT state.
  • As soon as the client receives the reply from the server, it will go to the FIN-WAIT-2 state.

termination of a connection is a four-way handshake. its terminated on both end at the same time. This happens directly after the server sent its last ACK.

  • The server is still in the CLOSE-WAIT state and it will independently follow up with a FIN, which updates the state to LAST-ACK.
  • Now the client receives the termination request and replies with an ACK, which results in a TIME-WAIT state.
  • The server sets the connection to CLOSED immediately.
  • The client stays in the TIME-WAIT state for a maximum of four minutes before setting the connection to CLOSED as well.

There’s also a three-way handshake alternative available, which occurs when the server sends its ACK+FIN in one single packet (server goes from ESTABLISHED to LAST-ACK in a single step).

So This is TCP.

points to remember about TCP

  • it’s a connection-oriented protocol
  • Verifies data is revived properly, if not resents it.
  • establish a connection before transmitting data and should close the connection after transmitting the data
  • 3-step authentication for Initialising a communication
  • 4-step authentication for Terminating a communication
  • Little bit slow when compared to UDP
  • TCP provides extensive error checking mechanisms. It is because it provides flow control and acknowledgment of data.

eg: HTTP, HTTPs, FTP, SMTP and Telnet

What is UDP ?

User Datagram Protocol is a Datagram oriented protocol. This is because there is no overhead for opening a connection, maintaining a connection, and terminating a connection. UDP is efficient for broadcast and multicast type of network transmission.

How Does UDP Work ?

UDP sends data from host to destination, without any initialization or alerts. So it’s fast, but there is no surety of data transfer. There is no retransmission of lost packets in the User Datagram Protocol (UDP).UDP supports Broadcasting.

Eg: DNS, DHCP, TFTP, SNMP, RIP, and VoIP.