From the course: Network Programming in C: Develop Reliable Client/Server Applications

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Accept multiple connections

Accept multiple connections

- [Instructor] You have several choices to enable a TCP server to accept and manage multiple, simultaneous connections. For example, you can disable the blocking on the accept or receive function calls. Then have the server poll open sockets looking for incoming data. You can fork the server, spawning a child process for each new connection. These approaches work, but they have various drawbacks I won't get into. The approach I use employs the select function to monitor multiple open sockets or file descriptors. These file descriptors are referenced in a set, an fd_set data type, which works like an array. The select function manages the data in the set and reports which file descriptors are ready to be read. This operation is complex, but it's a solid way for a server to manage multiple clients. The select function has five arguments: the highest-numbered file descriptor, plus one, an fd_set variable for the file…

Contents