Refactor server

Added new functions: `wait_server4` and `accept_server4` and by that
moved most of the code (handling new connections) to `main.c`.