I am using eclipse milo java OPCUA client SDK in our app for OPC implementation. I am able to create session, subscription and monitor. It is working fine but when opc server restarts and I try to delete previous session and create a new one with same parameters I get the below exception:
UaException: status=Bad_Timeout, message=timed out waiting for acknowledge
The line which throws the error is:
EndpointDescription[] endpoints = UaTcpStackClient.getEndpoints(endpointurl).get();
On server side I get the error:
OPCUAServerEndPoint#_on_client_connection The maximum number of connection has b een reached - Connection is refused
However, when I try to create the session again with same parameters it does get created
You shouldn't be creating a session by yourself as this is handled for you by the client, and you definitely shouldn't be trying to delete the previous session.
The only thing you need to do is add a
SubscriptionListener
to theOpcUaSubscriptionManager
and handle theonSubscriptionTransferFailed
callback.Receiving this callback means that the client has reconnected and had to create a new session, but the server was unable to transfer its old subscriptions to this session. This usually happens when either it took too long to reconnect and the subscriptions timed out or if something causes the server to lose all of its state, e.g. it gets restarted.
I've added a somewhat convoluted integration test that demonstrates that all of this does indeed work, you can see it here.