Adding code to initialize socket and close it at program termination