Move socket initialization to a single place