Opc.Ua.Bindings.TcpTransportChannel.Reconnect C# (CSharp) Method

Reconnect() public method

Closes any existing secure channel and opens a new one.
Calling this method will cause outstanding requests over the current secure channel to fail.
Thrown if any communication error occurs.
public Reconnect ( ) : void
return void
        public void Reconnect()
        {
            Utils.Trace("TcpTransportChannel RECONNECT: Reconnecting to {0}.", m_url);

            lock (m_lock)
            {
                // the new channel must be created first because WinSock will reuse sockets and this
                // can result in messages sent over the old socket arriving as messages on the new socket.
                // if this happens the new channel is shutdown because of a security violation.
                TcpClientChannel channel = m_channel;
                m_channel = null;
                
                // reconnect.
                OpenOnDemand();

                // begin connect operation.
                IAsyncResult result = m_channel.BeginConnect(m_url, m_operationTimeout, null, null);
                m_channel.EndConnect(result);

                // close existing channel.
                if (channel != null)
                {
                    try
                    {
                        channel.Close(1000);
                    }
                    catch (Exception)
                    {
                        // do nothing.
                    }
                    finally
                    {
                        channel.Dispose();
                    }
                }
            }
        }