Skip to main content

Understanding TCP & UDP

 TCP (Transmission Control Protocol) is stateful. This means it maintains a connection state between the communicating parties throughout the communication session.

Stateful Nature of TCP

  1. Connection Establishment: TCP requires a connection to be established between the sender and receiver before data transmission can begin. This is done through a process called the three-way handshake.

    • Three-Way Handshake: This process involves the exchange of three messages (SYN, SYN-ACK, and ACK) to establish a reliable connection.
  2. Maintaining State: During the connection, TCP keeps track of various parameters to ensure reliable and ordered data delivery.

    • Sequence Numbers: TCP assigns sequence numbers to each byte of data to ensure it is received in the correct order.
    • Acknowledgements (ACKs): The receiver sends acknowledgements for the received data packets. If an ACK is not received, the sender retransmits the data.
    • Flow Control: TCP uses a window mechanism to control the rate of data transmission based on the receiver's capacity.
    • Error Checking and Recovery: TCP includes error-checking mechanisms to detect and correct errors in data transmission.
  3. Connection Termination: TCP also manages the proper termination of the connection through a four-way handshake (FIN, FIN-ACK, ACK, ACK) to ensure all data is successfully transmitted and acknowledged before closing the connection.




n the context of the OSI (Open Systems Interconnection) model, TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) both operate at the Transport Layer (Layer 4). However, they have significant differences in how they handle data transmission. Here’s a comparison based on the OSI model:

TCP (Transmission Control Protocol)

  1. Layer: Transport Layer (Layer 4)
  2. Connection-Oriented: Establishes a connection between the sender and receiver before data transfer (Three-way handshake).
  3. Reliable: Ensures reliable data transfer with error checking, acknowledgment of received packets, and retransmission of lost packets.
  4. Flow Control: Uses flow control mechanisms to prevent network congestion and ensure that the sender does not overwhelm the receiver.
  5. Ordered Delivery: Ensures that data packets are delivered in the order they were sent.
  6. Error Checking: Provides extensive error checking using checksums.
  7. Overhead: Higher overhead due to connection establishment, maintenance, and error-checking mechanisms.
  8. Use Cases: Suitable for applications where reliability is critical, such as web browsing (HTTP/HTTPS), email (SMTP), and file transfers (FTP).

UDP (User Datagram Protocol)

  1. Layer: Transport Layer (Layer 4)
  2. Connectionless: Does not establish a connection before sending data. Each packet is sent independently.
  3. Unreliable: No guarantee of packet delivery. Packets may be lost, duplicated, or delivered out of order.
  4. No Flow Control: Does not manage the rate of data transmission, which can lead to packet loss during network congestion.
  5. No Ordered Delivery: Packets may arrive out of order, as each packet is treated independently.
  6. Error Checking: Provides basic error checking using checksums, but does not correct errors.
  7. Low Overhead: Lower overhead due to the lack of connection establishment, maintenance, and minimal error-checking mechanisms.
  8. Use Cases: Suitable for applications where speed is crucial and some data loss is acceptable, such as live video or audio streaming, online gaming, and Voice over IP (VoIP).


Comments

Popular posts from this blog

Ansible script to stop iptables

 Ansible script to stop iptables and disable during boot Step 1. [root@cluster playbooks]# pwd /root/playbooks [root@cluster playbooks]# cat hosts [webservers] 169.254.41.221 169.254.41.222 Step2. [root@cluster playbooks]# cat iptables.yml --- - name: stop ipatbles and disable   hosts: webservers   tasks:   - name: stop iptables     service: name=iptables state=stopped   - name: disbale on iptable on boot     service: name=iptables enabled=no Step3: [root@cluster playbooks]# ansible-playbook iptables.yml PLAY [stop ipatbles and disable] *********************************************** TASK [setup] ******************************************************************* ok: [169.254.41.222] ok: [169.254.41.221] ok: [localhost] TASK [stop iptables] *********************************************************** changed: [localhost] ok: [169.254.41.221] ok: [169.254.41.222] TASK [disbale on iptable on boot] ********************************************** ok: [169.254.41.222] changed: [localhost

Get information about remote hosts using Ansible

Get information about remote hosts using Ansible setup command Below command gives all the information of client hosts which includes memory, server architecture, IP adresses etc. [root@ansible mywork]# ansible all -i hosts -m setup If you need just memory information of remote node then for the above command need to add filter as shown below [root@ansible mywork]# ansible all -i hosts -m setup -a "filter=ansible_*_mb" node01 | SUCCESS => {     "ansible_facts": {         "ansible_memfree_mb": 873,         "ansible_memory_mb": {             "nocache": {                 "free": 919,                 "used": 77             },             "real": {                 "free": 873,                 "total": 996,                 "used": 123             },             "swap": {                 "cached": 0,                 "free": 15

connect: Network is unreachable

connect: Network is unreachable If you are getting below error, then probably you have not added gateway address or you have incorrect gateway in config file. [root@cluster ~]# ping google.com connect: Network is unreachable Before: [root@cluster ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth3 DEVICE=eth3 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.174.130 NETMASK=255.255.255.0 After: [root@cluster ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth3 DEVICE=eth3 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=static IPADDR=192.168.174.130 NETMASK=255.255.255.0 GATEWAY=192.168.174.2 [root@cluster ~]# ifdown eth3 [root@cluster ~]# ifup eth3 Determining if ip address 192.168.174.130 is already in use for device eth3... [root@cluster ~]# ping google.com PING google.com (216.58.218.174) 56(84) bytes of data. 64 bytes from dfw06s46-in-f14.1e100.net (216.58.218.174): icmp_seq=1 ttl=128 time=261 ms 6