8:58, EEST
October 18, 2021
Hi all ,
I am trying out with java prosys-opc-ua-sdk-client-server-evaluation-4.3.0 .
I am ale to create a connection. I have noticed that on connection failure or fault reconnect is triggered on server status change.
Would like to know how we can control this reconnect functionality ? Is there any way to check the reconnect attempt and disconnect from server ?
I tried with client.setAutoReconnect(true);
Also found in documentation that we could set it false and manually trigger reconnect, so question here again is the behavior of reconnect!
For now we look in ServerStatusListener and onStateChange i would need to send a notification to our Front end application, and the use case is only to try reconnecting in less than 2 min, if not terminate any active connections.
Appreciate any leads on this
Thanks in advance
Aneeta
15:09, EEST
Moderators
February 11, 2020
Hello,
You can reconnect manually with client.reconnect IF you have first disabled auto-reconnect with client.setAutoReconnect(false).
If you wish to try reconnecting only for a limited amount of time, you can use onStateChange of ServerStatusListener to detect the state of Server changing from Running to CommunicationFault to start a thread that attempts to reconnect for two minutes and then stops reconnecting if it hasn’t succeeded in reconnecting by that time.
11:17, EET
February 21, 2014
Hello,
when the client is in autoReconnect mode, will it try to reuse the previous session or start a new one? In case the server has been restarted using new certificates, a reconnect with the same endpoint information (which obviously caches the certificate info) will not succeed.
I am trying to work around this by monitoring the serverState (as described above). When the state goes from running to anything else, I call UaClient.disconnect(10ms) and immediately after UaClient.connect(). This though exposes a timing problem, as apparently the call to UaClient.isConnected() sometimes returns true even though the server is actually not running.
Many thanks,
Hans-Uwe
PS: I am using the Prosys SimulationServer for testing the client behaviour. Could it be possible that the server is still connectable even after its serverState transitioned to Shutdown?
16:16, EET
April 3, 2012
Hi,
There are quite many things to cover in this answer..
Do you have an actual (real) case where a Server would change it’s certificate like this? In practice this has not been an expected scenario for like …15 years. Basically the world is waiting for a real GDS implementation and hopefully we are soon there.
Anyway, UaClient does cache the EndpointDescription, that can be reset by calling client.setEndpoint(null) (make sure it is not connected or it will throw). Though I should note that we have not tested it in a scenario like this.
Normally if AutoReconnect is true you should not do any disconnect/connect/reconnect operations manually except the first connect() call (or more, if the initial one fails). Though, if the server _really_ change it’s certificate that wont help.
The shutdown state doesn’t change anything i.e. it is connectable until the period ends. Once that happens the connections are closed. We could maybe improve this in the future..
The UaClient will try to re-use things as much as possible, but it would make a new Session if the older cannot be reactivated (and same goes for the SecureChannel as well).
The isConnected “doesn’t mean” do we have an active connection “exactly right now”, javadocs:
“Are we connected to the server?
isConnected is changed by calling connect() or disconnect().
When isConnected, getSession returns a valid session. In other words, isConnected=(getSession() != null)
When isConnected, also check getServerState() to check if the server is actuallyrunning. If communication fails, isConnected will still return true, but getServerState() will give ServerState.CommunicationFault.
Returns:true when we are connected to the server, false otherwise.”
However… that might not be so clear anymore as I too have mistaken it sometimes as the wording .. is not very optimal (we need to revisit that as well in the future…). I guess you could say it is a bit like: https://docs.oracle.com/javase/8/docs/api/java/net/Socket.html#isConnected– (though for UaClient if it is disconnected manually it would also mean the Session doesn’t exist anymore and isConnected would return then false). But normally after the initial connection the Session itself might still be valid on the server even if there is a temporary connection break and sometimes it is possible to re-ActivateSession it.
14:02, EET
February 21, 2014
Thank you very much for the detailed answers.
We indeed have a use case for updating certificates “on the fly”: an aggregation server is connected to multiple underlying servers. If such underlying server is updated by a new version, the certificates are also updated but the aggregation server must seamlessly continue to operate after trusting the new certificates.
I will overwrite the isConnected() method in my custom client as suggested with uaClient.isConnected() && uaClient.getServerState() != Running
Many thanks, Hans-Uwe
17:28, EET
December 21, 2011
You mean ‘== Running’, I guess? 😉
And yes, it’s a bit complicated to use, but isConnected() is used also internally to detect if reconnections should happen, so therefore there is this diasctintion that if you have connected, you are connected until you disconnect. And everything else is just a temporary disruption.
But the certificate renewal can break this badly, if connect (or even reconnect) doesn’t work after that. It would be better to not cache the endpoint at all – or at least automatically refresh the cache if the connection fails.
Most Users Ever Online: 1919
Currently Online:
16 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 735
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1523
Posts: 6449
Newest Members:
rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmons, AnnelCib, dalenegettinger, howardkennerley, Thomassnism, biancacraft16Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1026, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1