code: def __connect(self):
          
          try:
              logger.debug("Socket connecting to %s:%s", self.host, self.port)
              self.sock.connect((self.host, self.port))
          except socket.error as e:
              logger.exception("socket error %s", e)
              logger.error("Closing socket and recreating a new one.")
              self.sock.close()
              self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
              self.sock.connect((self.host, self.port))
docs: A helper function to make connection.