System.Net.Sockets.TcpClient.EndConnect C# (CSharp) Method

EndConnect() public method

public EndConnect ( IAsyncResult asyncResult ) : void
asyncResult IAsyncResult
return void
        public void EndConnect(IAsyncResult asyncResult)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this, asyncResult);

            Socket s = Client;
            if (s == null)
            {
                // Dispose nulls out the client socket field.
                throw new ObjectDisposedException(GetType().Name);
            }

            EndConnectCore(s, asyncResult);

            _active = true;

            if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
        }

Usage Example

Exemplo n.º 1
0
        /// <summary>
        /// Methode callback appelée lorsque la connexion est effective.
        /// </summary>
        /// <param name="result"></param>
        private void OnConnect(IAsyncResult result)
        {
            try
            {
                _tcpClient.EndConnect(result);

                _connected = true;

                NetworkStream stream = _tcpClient.GetStream();
                if (stream != null)
                {
                    stream.BeginRead(_buffer, 0, _buffer.Length, OnDataReceived, this);

                    if (this.ReferenceDelegate != null)
                    {
                        this.ReferenceDelegate.OnConnect(this);
                    }
                }
            }
            catch (Exception e)
            {
                if (this.ReferenceDelegate != null)
                {
                    this.ReferenceDelegate.OnError(e, this);
                }
            }
        }
All Usage Examples Of System.Net.Sockets.TcpClient::EndConnect