Socket Multiplexing
If an application tries to read from a socket whose buffers are empty or tries to write to a socket whose buffers are full, the socket will normally block or stop the application until it can complete the operation. This is a problem if your application uses more than one socket at a time.
For example, an application could create two open sockets, s1 and s2, that display any data that arrives on a socket. Initially, data is not available on either socket. If the application reads from s1, execution blocks until data is available on that socket. In the meantime, data could arrive on s2, but the program would never receive it because the program is waiting for s1.
The solution is to block on both sockets simultaneously. The following sections explain how.