python socket wrapper for managing connections