Opc.Ua.Bindings.TcpServerChannel.Attach C# (CSharp) Method

Attach() public method

Attaches the channel to an existing socket.
public Attach ( uint channelId, Socket socket ) : void
channelId uint
socket Socket
return void
        public void Attach(uint channelId, Socket socket)
        {
            if (socket == null) throw new ArgumentNullException("socket");

            lock (DataLock)
            {
                // check for existing socket.
                if (Socket != null)
                {
                    throw new InvalidOperationException("Channel is already attached to a socket.");
                }
                
                ChannelId = channelId;
                State = TcpChannelState.Connecting;

                Socket = new TcpMessageSocket(this, socket, BufferManager, Quotas.MaxBufferSize);
                Utils.Trace("TCPSERVERCHANNEL SOCKET ATTACHED: {0:X8}, ChannelId={1}", Socket.Handle, ChannelId);
                Socket.ReadNextMessage();

                // automatically clean up the channel if no hello recieved.
                StartCleanupTimer(StatusCodes.BadTimeout);
            }
        }  

Usage Example

コード例 #1
0
        /// <summary>
        /// Handles a new connection.
        /// </summary>
        private void OnAcceptIPv6(IAsyncResult result)
        {
            TcpServerChannel channel = null;

            lock (m_lock)
            {
                // check if the socket has been closed.
                if (m_listeningSocketIPv6 == null)
                {
                    return;
                }

                try
                {
                    // accept the socket.
                    Socket socket = m_listeningSocketIPv6.EndAccept(result);

                    // create the channel to manage incoming messages.
                    channel = new TcpServerChannel(
                        m_listenerId,
                        this,
                        m_bufferManager,
                        m_quotas,
                        m_serverCertificate,
                        m_descriptions);
                    //channel.ServerCertificateChain = m_serverCertificateChain;

                    // start accepting messages on the channel.
                    channel.Attach(++m_lastChannelId, socket);

                    // save the channel for shutdown and reconnects.
                    m_channels.Add(m_lastChannelId, channel);

                    if (m_callback != null)
                    {
                        channel.SetRequestReceivedCallback(new TcpChannelRequestEventHandler(OnRequestReceived));
                    }

                    // Utils.Trace("Channel {0} created.", m_lastChannelId);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error accepting a new connection.");
                }

                // go back and wait for the next connection.
                try
                {
                    m_listeningSocketIPv6.BeginAccept(OnAcceptIPv6, null);
                }
                catch (Exception e)
                {
                    Utils.Trace(e, "Unexpected error listening for a new IPv6 connection.");
                }
            }
        }
All Usage Examples Of Opc.Ua.Bindings.TcpServerChannel::Attach