Opc.Ua.Client.Session.OnKeepAlive C# (CSharp) Method

OnKeepAlive() private method

Sends a keep alive by reading from the server.
private OnKeepAlive ( object state ) : void
state object
return void
        private void OnKeepAlive(object state)
        {            
           ReadValueIdCollection nodesToRead = (ReadValueIdCollection)state;
         
            try
            {
                // check if session has been closed.
                if (!Connected)
                {
                    return;
                }

                // raise error if keep alives are not coming back.
                if (KeepAliveStopped)
                {
                    if (!OnKeepAliveError(ServiceResult.Create(StatusCodes.BadNoCommunication, "Server not responding to keep alive requests.")))
                    {
                        return;
                    }
                }
                
                // limit the number of keep alives sent.
                if (OutstandingRequestCount > SubscriptionCount + 10)
                {
                    return;
                }

                RequestHeader requestHeader = new RequestHeader();

                requestHeader.RequestHandle     = Utils.IncrementIdentifier(ref m_keepAliveCounter);
                requestHeader.TimeoutHint       = (uint)(KeepAliveInterval*2);
                requestHeader.ReturnDiagnostics = 0;

                IAsyncResult result = BeginRead(
                    requestHeader,
                    0,
                    TimestampsToReturn.Neither,
                    nodesToRead,
                    OnKeepAliveComplete,
                    nodesToRead);

                AsyncRequestStarted(result, requestHeader.RequestHandle, DataTypes.ReadRequest);
            }
            catch (Exception e)
            {
                Utils.Trace("Could not send keep alive request: {1} {0}", e.Message, e.GetType().FullName);
            }
        }

Same methods

Session::OnKeepAlive ( ServerState currentState, System.DateTime currentTime ) : void