class_docstr: Implements a python interface to interact with the SC2 binary.
  
  All of these are implemented as blocking calls, so wait for the response
  before returning.
  
  Many of these functions take a Request* object and respond with the
  corresponding Response* object as returned from SC2. The simpler functions
  take a value and construct the Request itself, or return something more useful
  than a Response* object.
docstr: Connect to the websocket, retrying as needed. Returns the socket.
docstr_tok: ["Connect","to","the","websocket",",","retrying","as","needed",".","Returns","the","socket","."]
code: def _connect(self, host, port, proc, timeout_seconds):
      """Connect to the websocket, retrying as needed. Returns the socket."""
      if ":" in host and not host.startswith(
          "["
      ):  # Support ipv6 addresses.
          host = "[%s]" % host
      url = "ws://%s:%s/sc2api" % (host, port)
  
      was_running = False
      for i in range(timeout_seconds):
          is_running = proc and proc.running
          was_running = was_running or is_running
          if (
              i >= timeout_seconds // 4 or was_running
          ) and not is_running:
              logging.warning(
                  "SC2 isn't running, so bailing early on the websocket connection."
              )
              break
          logging.info(
              "Connecting to: %s, attempt: %s, running: %s",
              url,
              i,
              is_running,
          )
          try:
              return websocket.create_connection(
                  url, timeout=timeout_seconds
              )
          except socket.error:
              pass  # SC2 hasn't started listening yet.
          except websocket.WebSocketConnectionClosedException:
              raise ConnectError(
                  "Connection rejected. Is something else connected?"
              )
          except websocket.WebSocketBadStatusException as err:
              if err.status_code == 404:
                  pass  # SC2 is listening, but hasn't set up the /sc2api endpoint yet.
              else:
                  raise
          time.sleep(1)
      raise ConnectError(
          "Failed to connect to the SC2 websocket. Is it up?"
      )
  
imports: import copy
  import functools
  import socket
  import sys
  import time
  from absl import flags
  from absl import logging
  from pysc2.lib import protocol
  from pysc2.lib import static_data
  from pysc2.lib import stopwatch
  import websocket
  from s2clientprotocol import debug_pb2
  from s2clientprotocol import sc2api_pb2
label_desc: Use image node_id 2 for calling the RemoteController obj's underlying member method code with example usage: obj._connect(host, port, proc, timeout_seconds) and returns: websocket