The chat room program can be said to be the simplest multi-point communication program. There are many implementation methods for chat room, but all use so-called "multi-user space" to exchange information, with typical multi-channel I / O architectures. A simple chat room, from the programmer's point of view, is a multi-to-many communication between multiple I / O endpoints. Its core is multiple-way I / O communication. Multi-channel I / O communication is also known as I / O multiplex (I / O multiplexing) Under UNIX / Linux, there are 5 I / O models:
l blocking I / O
l Non-blocking I / O
L I / O multiplexing (SELECT and POLL)
l Signal Drive I / O (SIGIO)
l Asynchronous I / O (POSIX.1 AIO_ series function)
Since multiplex I / O is handled, the blocking method is clearly unsatisfactory. Non-blocking I / O uses polling, and it is a lot of waste on CPU time. For signal drivers (SIGIO) and asynchronous I / O methods: First, asynchronous I / O is based on signaling mechanism, not reliable; secondly single signal is not sufficient to provide more information sources, or need to assist other means, It has a high difficulty in achieving. For more than the intelemer, the non-blocking I / O and SELECT methods are tested, and the final choice is SELECT. It is easy to use, and it takes up less system resources. Source code download: http://bbs1.nju.edu.cn/file/n/nsun/chatsrc.rar