We need to follow the best practice of writing a client-server program. The best guide that I can recommend for you right now is Problem C10K . In this case, we need specific things. We can use choice or poll or epoll. Each has its own advantages and disadvantages.
If you use code using the latest kernel version, I would recommend going for epoll. Click to see an example program to understand epoll .
If you use select, poll, epoll, then you will be blocked until you receive an event / trigger so that your server does not work in an infinite loop, consuming your system time.
In my personal experience, I think that epoll is the best way to go further, because I noticed that the threshold of my server machine with 80K ACTIVE connection was very low when compared, it will select and poll. The average load on my server machine was only 3.2 with an active 80k connection :)
When testing with a survey, I find that the average server load increased to 7.8 when reaching an active client connection of 30,000: (.
source share