Sunday, November 19, 2017

TCP AND UDP


Datagram communication: (UDP)
The datagram communication protocol, known as UDP (user datagram protocol), is a connectionless protocol, meaning that each time you send datagrams, you also need to send the local socket descriptor and the receiving socket's address. As you can tell, additional data must be sent each time a communication is made.

Stream communication: (TCP)
The stream communication protocol is known as TCP (transfer control protocol). Unlike UDP, TCP is a connection-oriented protocol. In order to do communication over the TCP protocol, a connection must first be established between the pair of sockets. While one of the sockets listens for a connection request (server), the other asks for a connection (client). Once two sockets have been connected, they can be used to transmit data in both (or either one of the) directions.



TCP (Transmission Control Protocol) is a connection-based protocol that provides a reliable flow of data between two computers. It guarantees that the sent data are not lost and arrive in the proper order to the receiver.

UDP (User Datagram Protocol) is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantees about arrival. UDP is not connection-based like TCP. Datagrams may arrive to the receiver in an arbitrary order, some of them might be lost.

Identification of hosts in the network is made using IP (Internet Protocol) addresses. An IP address is a 32-bit number (or a 128-bit for IPv6) typically represented using the dot notation as a sequence of four (or eight) numbers separated with dots (e.g. 192.33.71.12). A human-friendly identification of hosts involves DNS (Domain Name Service) which gives them names like: "edu.pjwstk.edu.pl".

Such an identification is not enough for inter-process communication, as there may be several processes running on a host. TCP and UDP protocols use ports for delivering data to a receiver. A port is identified by a 16-bit number.

In connection-based communication such as TCP, a server application binds a socket to a specific port number. This has the effect of registering the server with the operating system to receive all data destined for that port. A client can then talk with the server at the server's port.



DIFFERENCE BETWEEN TCP AND UDP
  • TCP is a connection-oriented protocol, on the other hand, a connection must be established before communications between the pair of sockets start. So there is a connection setup time in TCP.
  • UDP, there is a size limit of 64 kilobytes on datagrams you can send to a specified location, while in TCP there is no limit. Once a connection is established, the pair of sockets behaves like streams: All available data are read immediately in the same order in which they are received.
  • UDP is an unreliable protocol -- there is no guarantee that the datagrams you have sent will be received in the same order by the receiving socket.
  • TCP is a reliable protocol; it is guaranteed that the packets you send will be received in the order in which they were sent.
  • TCP is useful for implementing network services -- such as remote login (rlogin, telnet) and file transfer (FTP) -- which require data of indefinite length to be transferred.
  • UDP is less complex and incurs fewer overheads. It is often used in implementing client/server applications in distributed systems built over local area networks.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.