Sockets are a low-level network interface that helps in creating a connection between two program mainly clients which may or may not be running on the same machine.
Socket Programming is one of the most widely used networking concepts.
There are two types of Internet Protocol Traffic -
1. TCP - Transmission Control Protocol
2. UDP - User Datagram Protocol
TCP is a connection-oriented protocol.
UDP is a connectionless protocol.
TCP is suited for applications that require high reliability, and transmission time is relatively less critical.
UDP is suitable for applications that need fast, efficient transmission, such as games. UDP's stateless nature is also useful for servers that answer small queries from huge numbers of clients.
In simpler words -
Use TCP when you cannot afford to loose data and when time to send and receive data doesn't matter.
Use UDP when you cannot afford to loose time and when loss of data doesn't matter.
There is an absolute guarantee that the data transferred remains intact and arrives in the same order in which it was sent in case of TCP.
whereas there is no guarantee that the messages or packets sent would reach at all in UDP.