Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
UaClient - reconnect
October 21, 2021
8:58, EEST
Avatar
aneeta.antony@bakerhughes.com
New Member
Members
Forum Posts: 2
Member Since:
October 18, 2021
sp_UserOfflineSmall Offline

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

October 22, 2021
15:09, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 319
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

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.

December 8, 2021
11:17, EET
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

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?

December 8, 2021
16:16, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 982
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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.

December 9, 2021
14:02, EET
Avatar
hbrackel
Member
Members
Forum Posts: 135
Member Since:
February 21, 2014
sp_UserOfflineSmall Offline

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

December 9, 2021
17:28, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

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.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
12 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

ibrahim: 75

rocket science: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

TimK: 41

Member Stats:

Guest Posters: 0

Members: 707

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1466

Posts: 6253

Newest Members:

christi10l, ahamad1, Flores Frederick, ellenmoss, harriettscherer, shanonhumphreys, KupimotoblokfuB, tamhollander5, paulinafcf, bridgette18l

Moderators: Jouni Aro: 1009, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 982, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 319, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1