kevinherron / ua-client-sdk

OPC-UA Client SDK for Java
27 stars 16 forks source link

UaException: status=Bad_Timeout, message=request timed out after 5000ms #11

Closed wsuetholz closed 6 years ago

wsuetholz commented 6 years ago

Really not a bug report as such.. More a plea for information on what I need to change to set this to 60000ms instead? In an attempt to do this I've recently added the "timeout = new Long(60000);" and ".setAcknowlegeTimeout(uint(timeout))" lines. With wireshark I see the connection and the authentication negotiations happening, but the timeout occurs while that negotiation is going on. Using the UAExpert client I've clocked the connect time from a low of 8 seconds to higher than the 10 seconds that UAExpert allows for. I've inquired with the vendor in order to speed up their side, but not getting much hope that they will be able to speed their end up enough. The code used to start the connection is below. The exception at the end of the startup method is what is seen in my logs.

` private static EndpointDescription updateEndpointUrl( EndpointDescription original, String hostname) throws URISyntaxException {

    URI uri = new URI(original.getEndpointUrl()).parseServerAuthority();

    String endpointUrl = String.format(
            "%s://%s:%s%s",
            uri.getScheme(),
            hostname,
            uri.getPort(),
            uri.getPath()
    );

    return new EndpointDescription(
            endpointUrl,
            original.getServer(),
            original.getServerCertificate(),
            original.getSecurityMode(),
            original.getSecurityPolicyUri(),
            original.getUserIdentityTokens(),
            original.getTransportProfileUri(),
            original.getSecurityLevel()
    );
}

public void startup() {
    URI uri = null;
    try {
        uri = new URI (url);
    } catch (Exception ex) {
        logger.error("Parse URL to URI Exception:" + ex.getLocalizedMessage());
    }
    String hostname = "localhost";
    int portnum = 56000;

    if (uri != null) {
        hostname = uri.getHost();
        portnum = uri.getPort();
    }

    CompletableFuture<UaClient> request = null;
    logger.info("Startup PbOpcUaClient \"" + url + "\"");

    timeout=new Long(60000);

    try {

// EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints("opc.tcp://localhost:12686/test-server").get(); EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints(url).get(); EndpointDescription endpoint = Arrays.stream(endpoints) .filter(e -> e.getSecurityPolicyUri().equals(SecurityPolicy.None.getSecurityPolicyUri())) .findFirst().orElseThrow(() -> new Exception("no desired endpoints returned"));

        endpoint = updateEndpointUrl(endpoint, hostname);

        KeyStoreLoader loader = new KeyStoreLoader().load();

        OpcUaClientConfig clientConfig = OpcUaClientConfig.builder()
                .setApplicationName(LocalizedText.english(appName))
                .setApplicationUri(OPC_URI_LEADIN + appUri)
                .setCertificate(loader.getClientCertificate())
                .setKeyPair(loader.getClientKeyPair())
                .setEndpoint(endpoint)
                .setRequestTimeout(uint(timeout))
                .setAcknowledgeTimeout(uint(timeout))
                .setSessionTimeout(uint(timeout))
                .setIdentityProvider(new UsernameProvider(username, password))
                .build();

        opcUaClient = new OpcUaClient(clientConfig);
        opcUaClient.addFaultListener(this);
        request = opcUaClient.connect();
        uaClient = request.get(60L, TimeUnit.SECONDS);
        if (uaClient == null) {
            connected = false;
        } else {
            connected = true;
            uaSession = uaClient.getSession().get();
        }

        //client.browse();
        logger.info("Client is now Connected.");
    } catch (Exception ex) {
        logger.error("Exception Caught Connecting: \"" + ex.getLocalizedMessage() + "\"");
    }
}

`

kevinherron commented 6 years ago

Did you mean to post this over at https://github.com/eclipse/milo or are you really using this library/repo still?

wsuetholz commented 6 years ago

Probably should be there... Should I repost?

kevinherron commented 6 years ago

Please do. Be careful with the code formatting and separating the question, and provide the exception in a code block as well if you can.