def remote_access(client, params):
    """
    Start relay which will attempt to connect to a Cloud service and a local
    service and securely tunnel information between the two. Used primarily for
    Telnet.
    """
    url = params["url"]
    host = params["host"]
    protocol = int(params["protocol"])

    if not check_listening_port(host, protocol):
        return (iot.STATUS_FAILURE,
                "Error: port (%d) not listening" % protocol)

    secure = client.config.validate_cloud_cert is not False
    try:
        relay.create_relay(url,
                           host,
                           protocol,
                           secure=secure,
                           log_func=client.log)
        return (iot.STATUS_SUCCESS, "")
    except Exception as error:
        client.error(str(error))
        return (iot.STATUS_FAILURE, str(error))
def remote_access(client, params):
    """
    Start relay which will attempt to connect to a Cloud service and a local
    service and securely tunnel information between the two. Used primarily for
    Telnet.  Parameters:
        url:
            long URL containing all the details to talk to the micro
            service.
        host:
            default is localhost
        protocol port:
            values defined in iot.cfg
        reconnect:
            Optional.  The default is false.  Some services disconnect
            after some time.  reconnect=True will reconnect the local
            socket if it drops.  E.g. http drops the socket after a
            connect.
    """
    if not 'url' in params.keys():
        return (iot.STATUS_FAILURE, "url parameter missing")
    elif not 'host' in params.keys():
        return (iot.STATUS_FAILURE, "host parameter missing")

    url = params["url"]
    host = params["host"]
    protocol = int(params["protocol"])
    reconnect = False
    if "reconnect" in params.keys():
        reconnect = params["reconnect"]

    if not check_listening_port(client, host, protocol):
        client.event_publish(
            "Error: local port {} not listening".format(protocol))
        return (iot.STATUS_FAILURE,
                "Error: port (%d) not listening" % protocol)

    secure = client.config.validate_cloud_cert is not False

    # pass in the proxy info to the websocket lib
    if client.config.proxy:
        proxy = client.config.proxy
    else:
        proxy = None

    try:
        relay.create_relay(url,
                           host,
                           protocol,
                           secure=secure,
                           log_func=client.log,
                           local_socket=client.handler.original_socket,
                           reconnect=reconnect,
                           proxy=proxy)
        return (iot.STATUS_SUCCESS, "")
    except Exception as error:
        client.error(str(error))
        return (iot.STATUS_FAILURE, str(error))