Add socket creation to the server code.
Improve robustness of daemon lifecycle.