locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
475 stars 128 forks source link

Client connect error:BadNonceInvalid #299

Closed LongZoz closed 7 months ago

LongZoz commented 7 months ago

I use the client created by opcua-master\samples\simple-client to connect to the local server (security model: None), the connection Got an error while creating the default session - BadNonceInvalid. Here is my code, just modifying the target url, the local server is Prosys opc ua simulation server

fn main() -> Result<(), ()> {
    // Read command line arguments
    let args = Args::parse_args().map_err(|_| Args::usage())?;
    if args.help {
        Args::usage();
    } else {
        // Optional - enable OPC UA logging
        opcua::console_logging::init();

        // Make the client configuration
        let mut client = ClientBuilder::new()
            .application_name("Simple Client")
            .application_uri("urn:SimpleClient")
            .product_uri("urn:SimpleClient")
            .trust_server_certs(true)
            .create_sample_keypair(true)
            .session_retry_limit(3)
            .client()
            .unwrap();
        println!("123");
        if let Ok(session) = client.connect_to_endpoint(
            (
                // args.url.as_ref(),
                "opc.tcp://Zwl:53530/OPCUA/SimulationServer",
                SecurityPolicy::None.to_str(),
                MessageSecurityMode::None,
                UserTokenPolicy::anonymous(),
            ),
            IdentityToken::Anonymous,
        ) {
            println!("456");
            if let Err(result) = subscribe_to_variables(session.clone(), 2) {
                println!(
                    "ERROR: Got an error while subscribing to variables - {}",
                    result
                );
            } else {
                // Loops forever. The publish thread will call the callback with changes on the variables
                let _ = Session::run(session);
            }
        }
    }
    Ok(())
}

This is my server configuration: image