Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrying connection to opcua Server #477

Open
vrushalikatkade opened this issue Feb 17, 2023 · 4 comments
Open

Retrying connection to opcua Server #477

vrushalikatkade opened this issue Feb 17, 2023 · 4 comments

Comments

@vrushalikatkade
Copy link

vrushalikatkade commented Feb 17, 2023

In node opcua server connection ,the following function will retrying to connect opc ua server ,if it is not available.
" client.on("backoff", () => console.log("retrying connection"));"

which function is used for retrying server connection in UA-.NETStandard. please mention the example

@mregen
Copy link
Contributor

mregen commented Feb 21, 2023

@vrushalikatkade Sorry, currently the SDK has no support for such function.

@vrushalikatkade
Copy link
Author

@mregen thanks for reply, actually i have windows service for connecting opcua server. in this service ,
after starting the computer the service try to connect to the server ,but if server is unavailable , then this function throws exception . I want wait for server connection until server active
i used following code
log.writelog("2 - Discover endpoints of OPC UA server.");
Uri endpointURI = new Uri(server.EndPointUrl);
var endpointCollection = DiscoverEndpoints(config, endpointURI, 10);
var selectedEndpoint = SelectUaTcpEndpoint(endpointCollection, certOK);

                        log.writelog("3 - Create a session with OPC UA server.");
                        var endpointConfiguration = EndpointConfiguration.Create(config);
                        var endpoint = new ConfiguredEndpoint(selectedEndpoint.Server, endpointConfiguration);
                        endpoint.Update(selectedEndpoint);

var session =await Opc.Ua.Client.Session.Create(config, endpoint, true, session1.Name, 60000, null, null);
session.KeepAlive += Client_KeepAlive;
session.TransferSubscriptionsOnReconnect = true;

@mregen
Copy link
Contributor

mregen commented Feb 22, 2023

@vrushalikatkade yes you can retry calling Session.Create, or you could retry calling SelectEndpoint which internally tries to reach the discovery endpoint until no timeout or exception occurs.

@vrushalikatkade
Copy link
Author

in Session.Create() function timeout set to 60000 but it will not wait for the server active within second through exception
exception:
Opc.Ua.ServiceResultException
HResult=0x80131500
Message=Error establishing a connection: BadNotConnected
Source=Opc.Ua.Core
StackTrace:
at Opc.Ua.Bindings.ChannelAsyncOperation`1.End(Int32 timeout, Boolean throwOnError)
at Opc.Ua.Bindings.UaSCUaBinaryClientChannel.EndSendRequest(IAsyncResult result)
at Opc.Ua.DiscoveryClient.GetEndpoints(RequestHeader requestHeader, String endpointUrl, StringCollection localeIds, StringCollection profileUris, EndpointDescriptionCollection& endpoints)
at Opc.Ua.DiscoveryClient.GetEndpoints(StringCollection profileUris)
at Opc.Ua.ConfiguredEndpoint.UpdateFromServer(Uri endpointUrl, ITransportWaitingConnection connection, MessageSecurityMode securityMode, String securityPolicyUri)
at Opc.Ua.ConfiguredEndpoint.UpdateFromServer()
at Opc.Ua.Client.Session.d__83.MoveNext()
at Opc.Ua.Client.Session.d__84.MoveNext()
at OPCUAConnector.Server_connection.d__5.MoveNext() in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants