Added catch for keyboard interrupt to close sockets before exiting