Opc.Ua.Bindings.TcpClientChannel.OnConnectComplete C# (CSharp) Method

OnConnectComplete() private method

Called when the socket is connected.
private OnConnectComplete ( object sender, SocketAsyncEventArgs e ) : void
sender object
e System.Net.Sockets.SocketAsyncEventArgs
return void
        private void OnConnectComplete(object sender, SocketAsyncEventArgs e)
        {
            WriteOperation operation = (WriteOperation) e.UserToken;

            // dual stack ConnectAsync may call in with null UserToken if 
            // one connection attempt timed out but the other succeeded
            if (operation == null) return;

            if (e.SocketError != SocketError.Success)
            {
                operation.Fault(StatusCodes.BadNotConnected);
                return;
            }

            lock (DataLock)
            {
                try
                {
                    // check for closed socket.
                    if (Socket == null)
                    {                        
                        operation.Fault(StatusCodes.BadSecureChannelClosed);
                        return;
                    }

                    // start reading messages.
                    Socket.ReadNextMessage();

                    // send the hello message.
                    SendHelloMessage(operation);
                }
                catch (Exception ex)
                {
                    ServiceResult fault = ServiceResult.Create(
                        ex, 
                        StatusCodes.BadTcpInternalError, 
                        "An unexpected error occurred while connecting to the server.");
                            
                    operation.Fault(fault);
                }
            }
        }