Thomas Thomas - 9 months ago 36
Linux Question

What kind of server needs select

I know that a server normally open one port and listen it.

Today I learnt that there was a function

in system Unix-Like. With
we can listen multi-sockets.

I just can't imagine a case where we need to use
. If we have two sockets, it means that we are listening two ports, right? So I have a question:

What kind of server would open more than one port but receive and process the same type of requests?


Using select helps with handling reads and writes on multiple sockets. It doesn't have to be multiple server sockets. The most typical use is for multiplexing a large number of client sockets.

You have a server with one listening socket. Each time you accept a connection, you add the new client socket to the multiplexing pool. select then returns any time any of those sockets has data available to read. The big win is that you're doing all this with one thread.