def connect(address, port, tunnel=False, authkey='PublicKey', pubkey=None,
            logfile=None):
    """
    Connects to the server at `address` and `port` using `key` and returns
    a (shared) proxy for the associated :class:`ObjServerFactory`.

    address: string
        IP address for server or pipe filename.

    port: int
        Server port.  If < 0, `address` is a pipe filename.

    tunnel: bool
        Connect via SSH tunnel.

    authkey:
        Server authorization key.

    pubkey:
        Server public key; required if `authkey` is 'PublicKey'.

    logfile:
        Location of server's log file, if known.
    """
    if port < 0:
        key = address
    else:
        key = (address, port)
    try:
        return _PROXIES[key]
    except __HOLE__:
        # Requires ssh setup.
        if tunnel:  # pragma no cover
            location, cleanup = setup_tunnel(address, port)
            atexit.register(*cleanup)
        else:
            location = key
        via = ' (via tunnel)' if tunnel else ''
        log = ' at %s' % logfile if logfile else ''
        if not OpenMDAO_Proxy.manager_is_alive(location):
            raise RuntimeError("Can't connect to server at %s:%s%s. It appears"
                               " to be offline. Please check the server log%s."
                               % (address, port, via, log))

        mgr = _FactoryManager(location, authkey, pubkey=pubkey)
        try:
            mgr.connect()
        except EOFError:
            raise RuntimeError("Can't connect to server at %s:%s%s. It appears"
                               " to be rejecting the connection. Please check"
                               " the server log%s." % (address, port, via, log))

        proxy = mgr.openmdao_main_objserverfactory_ObjServerFactory()
        if proxy.version != __version__:
            logging.warning('Server version %r different than local version %r',
                            proxy.version, __version__)
        _PROXIES[key] = proxy
        return proxy
dataset/ETHPy150Open OpenMDAO/OpenMDAO-Framework/openmdao.main/src/openmdao/main/objserverfactory.py/connect