 <p><code>alarm()</code> is not a good way to implement periodic events in a server. It functions as an asynchronous signal, and as such is difficult to handle appropriately while something else is going on. For instance, if your server is in the middle of sending a message to a client, having the alarm go off and start generating output would be likely to disrupt the message. Bottom line is, it's not the right way of going about this.</p> <p>Most client/server applications use the <code>select()</code> or <code>poll()</code> system calls at their core. These system calls allow your application to wait for an event to occur (e.g, data arriving) on any number of file descriptors, with an optional timeout. This is how most server applications handle connections with multiple clients at a time.</p> <p>Using these system calls is likely to require you to restructure your application around a "state machine" model, rather than using program flow to represent state. Explaining how to do this effectively is a larger task than is reasonable for a short answer such as this; prepare to do some research!</p>