Refactored server communication and argument parsing

Moved both into their own functions for easier maintenance and added the
option to set a port for the server.
Added connection error handling to client