Refactor and clean up

Refactored the server socket initialisation code into
init_server_socket(). Also cleaned up the functions in socket.c so they
make a bit more sense.