Split off server code to multiple files

Created a common header with extern global variable declarations.