Reconnecting on demand

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
danielcordoneanu
Jr. Member
Jr. Member
Posts: 3
Joined: 19 Jul 2017, 14:40

Reconnecting on demand

Post by danielcordoneanu »

Hello,

I have a somewhat odd question. Let's say I want to reconnect to a server on demand (reconnect automatically set to false). What is the correct behavior when trying to connect with the same session object? If the automatic reconnecting is set to true, then the server status is set to New session created and this is sent to the client. This however doesn't happen when trying to reconnect manually to the server (first I call disconnect on the session object and then connect).

I searched the forum, but couldn't find any answer on this topic.

Thanks,
Daniel

User avatar
Support Team
Hero Member
Hero Member
Posts: 3069
Joined: 18 Mar 2011, 15:09

Re: Reconnecting on demand

Post by Support Team »

Dear Daniel,

The information "New session created" is only relevant in the case of a reconnect. Therefore the initial connect does not inform you about this intermediate state since you know that you do the initial connect and you have to do your initial setup (read namespace, register nodes) anyhow.

In the case of a reconnect, the client library tries to reuse the previous session. If this is possible, no further action is necessary. If a new session was created during reconnect, the client application may need to do some action like re-register nodes.
Best regards
Unified Automation Support Team

danielcordoneanu
Jr. Member
Jr. Member
Posts: 3
Joined: 19 Jul 2017, 14:40

Re: Reconnecting on demand

Post by danielcordoneanu »

Hello again and thank you for the reply.
Support Team wrote:In the case of a reconnect, the client library tries to reuse the previous session. If this is possible, no further action is necessary. If a new session was created during reconnect, the client application may need to do some action like re-register nodes.
Regarding this. My question was more like how can I get the same behavior like reconnecting automatically?

Let's take 4 situations:
1. the server restarts and the client reconnects to it with bAutomaticReconnect = OpcUa_True. The client tries to reactivate the old session on the old server, but it can't => new session is created on the server => client gets notified that a new session was created

2. the server restarts and the client reconnects to it with bAutomaticReconnect = OpcUa_False (Client reconnects on demand when the user clicks on a button). The client has to call UaSession::disconnect first and then call UaSession::connect to reconnect to the server (if disconnect is not called, a BadInternalError is received because UaSession::IsConnected returns true I believe and the Session is destroyed automatically or so far that's what the logs say). When the client is reconnected in this way => server creates a new session => client is not notified that old session is gone => how do I know that the server was restarted?

3. the connection between the server and the client gets interrupted and the client reconnects to it with bAutomaticReconnect = OpcUa_True. The client reconnects successfully and the old session is activated => no need to do anything.

4. the connection between the server and the client gets interrupted and the client reconnects to it with bAutomaticReconnect = OpcUa_False. The client has to call UaSession::disconnect first and then call UaSession::connect to reconnect to the server (if disconnect is not called, a BadInternalError is received because UaSession::IsConnected returns true I believe and the Session is destroyed automatically or so far that's what the logs say). When disconnect is called, the session on the server's side is closed so the old session cannot be activated anymore? From what I see here there is no way that I can activate my old session.

Thank you,
Daniel

User avatar
Support Team
Hero Member
Hero Member
Posts: 3069
Joined: 18 Mar 2011, 15:09

Re: Reconnecting on demand

Post by Support Team »

Hello Daniel,

1) that's clear I guess

2)
When the client is reconnected in this way => server creates a new session => client is not notified that old session is gone => how do I know that the server was restarted?
When the client explicitly calls disconnect the session is gone. There's no difference for the client if the server was restarted or not.

3) OK

4) Correct. That's why we provide the feature automatic reconnect.
Best regards
Unified Automation Support Team

Post Reply