code: def _cmd(self, endpoint, cmd):
          
          cmdbuf = "%s\n" % (cmd)
          # some cmds have large outputs and ZK closes the connection as soon as it
          # finishes writing. so read in huge chunks.
          recvsize = 1 << 20
          replies = []
          host, port = endpoint
  
          ips = get_ips(host, port)
  
          if len(ips) == 0:
              raise self.CmdFailed("Failed to resolve: %s" % (host))
  
          for ip in ips:
              try:
                  with connected_socket((ip, port)) as sock:
                      sock.send(cmdbuf.encode())
                      while True:
                          buf = sock.recv(recvsize).decode("utf-8")
                          if buf == "":
                              break
                          replies.append(buf)
              except socket.error as ex:
                  # if there's only 1 record, give up.
                  # if there's more, keep trying.
                  if len(ips) == 1:
                      raise self.CmdFailed("Error(%s): %s" % (ip, ex))
  
          return "".join(replies)
docs: endpoint is (host, port)