There are several types of sockets. The most important classification is into datagram- and stream sockets.
Datagram sockets are connectionless. These sockets communicate using datagrams: small packages of data. There is no permanent connection between these sockets. Every write action sends a message which must be read by the receiver in one read action. Thus the boundaries between messages is visible to the sender and receiver and synchronisation of the messages is left to the sending and receiving program.
If you're using datagrams sockets you have to be aware that delivery of packages of data is not guaranteed. It is even possible to receive the same package more than once.
Stream sockets are connection-oriented, meaning that they will build up a connection over which data traffic can take place. Writing data to this type of sockets and reading data from them is like writing to or reading from a byte stream. There are no package boundaries and byte order is preserved by the transport system.
With stream sockets, correct delivery of data is guaranteed.
In the internet domain (AF_INET) the default protocol for stream sockets is TCP (transport control protocol) and for datagram sockets it is UDP (user datagram protocol). Hence we have tcp/ip and udp/ip.
Applications of sockets:
- I/O between processes
- I/O between processes on different computers in a network
- I/O between processes on different computers through the internet
- Load balancing
Assignment: equip the daemon with a message queue