Tuesday, February 4, 2020

Use of TCP/IP and UDP for socket programming

Transmission Control Protocol/Internet Protocol

TCP is a standard that defines how to establish and maintain a network connection through which application programs can exchange data, and this connection is established and maintained until the application programs at each end have finished exchanging messages. TCP determines how to break application data into packets that networks can deliver, sends packets to and accepts packets from the network layer, manages flow control and because it is meant to provide error-free data transmission, it handles re-transmission of dropped or garbled packets as well as acknowledgement of all packets that arrive. TCP works with Internet Protocol(IP). IP defines how computers send data packets to each other. Together, TCP and IP are the basic rules defining the internet, they are used for organizing data in a way that ensures the secure transmission between the server and client.

Fig. TCP\IP Model Layers

On a TCP/IP network every device must have an IP address. The IP address identifies the device e.g. computer. However an IP address alone is not sufficient for running network applications, as a computer can run multiple applications and/or servicesJust as the IP address identifies the computer, The network port identifies the application or service running on the computer.The use of ports allow computers/devices to run multiple services/applications. In simple words suppose, if you use a house or apartment, IP address will correspond to the street address. All of the apartments will share the same street address. However each apartment will also have an apartment number which will correspond to the Port number.

A socket is the combination of IP address plus port, as shown in above figure.

User Defined Protocol

TCP is for connection orientated applications whereas, UDP is for connection less applications. UDP is a simple transport-layer protocol. The application writes a message to a UDP socket, which is then encapsulated in a UDP datagram, which is further encapsulated in an IP datagram, which is sent to the destination. There is no guarantee that a UDP will reach the destination, that the order of the datagrams will be preserved across the network or that datagrams arrive only once. The problem of UDP is its lack of reliability: if a datagram reaches its final destination but the checksum detects an error, or if the datagram is dropped in the network, it is not automatically retransmitted.
Applications are designed to use either the UDP or TCP transport layer protocol depending on the type of connection they require. Because there is no connection setup, UDP is faster than TCP and results in less network traffic.
Thank you!!

35 comments:

  1. Very informative and helpful. Great piece of work!

    ReplyDelete
  2. Very informative and helpful..

    ReplyDelete