code: def connect(self, uid=UNKNOWN_UID, cmd=JsonRpcCommand.INIT):
          
          self._counter = self._id_counter()
          self._conn = socket.create_connection(('localhost', self.host_port),
                                                _SOCKET_CONNECTION_TIMEOUT)
          self._conn.settimeout(_SOCKET_READ_TIMEOUT)
          self._client = self._conn.makefile(mode='brw')
  
          resp = self._cmd(cmd, uid)
          if not resp:
              raise ProtocolError(self._ad,
                                  ProtocolError.NO_RESPONSE_FROM_HANDSHAKE)
          result = json.loads(str(resp, encoding='utf8'))
          if result['status']:
              self.uid = result['uid']
          else:
              self.uid = UNKNOWN_UID
docs: Opens a connection to a JSON RPC server.
  
          Opens a connection to a remote client. The connection attempt will time
          out if it takes longer than _SOCKET_CONNECTION_TIMEOUT seconds. Each
          subsequent operation over this socket will time out after
          _SOCKET_READ_TIMEOUT seconds as well.
  
          Args:
              uid: int, The uid of the session to join, or UNKNOWN_UID to start a
                  new session.
              cmd: JsonRpcCommand, The command to use for creating the connection.
  
          Raises:
              IOError: Raised when the socket times out from io error
              socket.timeout: Raised when the socket waits to long for connection.
              ProtocolError: Raised when there is an error in the protocol.