当前位置: 首页>>代码示例>>C#>>正文


C# ClientState.Dispose方法代码示例

本文整理汇总了C#中ClientState.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ClientState.Dispose方法的具体用法?C# ClientState.Dispose怎么用?C# ClientState.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ClientState的用法示例。


在下文中一共展示了ClientState.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnAuthenticate

        private void OnAuthenticate(Task result, ClientState state)
        {
            SslStream sslStream = (SslStream)state.Stream;

            try
            {
                result.GetAwaiter().GetResult();
                _log.WriteLine("Server authenticated to client with encryption cipher: {0} {1}-bit strength",
                    sslStream.CipherAlgorithm, sslStream.CipherStrength);

                // Start listening for data from the client connection.
                sslStream.BeginRead(state.ReceiveBuffer, 0, state.ReceiveBuffer.Length, OnReceive, state);
            }
            catch (AuthenticationException authEx)
            {
                _log.WriteLine(
                    "Server disconnecting from client during authentication.  No shared SSL/TLS algorithm. ({0})",
                    authEx);
            }
            catch (Exception ex)
            {
                _log.WriteLine("Server disconnecting from client during authentication.  Exception: {0}",
                    ex.Message);
            }
            finally
            {
                state.Dispose();
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:29,代码来源:DummyTcpServer.cs

示例2: OnAccept

        private void OnAccept(Task<TcpClient> result)
        {
            TcpClient client = null;

            // Accept current connection
            try
            {
                client = result.Result;
            }
            catch
            {
            }

            // If we have a connection, then process it
            if (client != null)
            {
                OnClientAccepted(client);

                ClientState state;

                // Start authentication for SSL?
                if (_useSsl)
                {
                    state = new ClientState(client, _sslEncryptionPolicy);
                    _log.WriteLine("Server: starting SSL authentication.");


                    SslStream sslStream = null;
                    X509Certificate2 certificate = TestConfiguration.GetServerCertificate();

                    try
                    {
                        sslStream = (SslStream)state.Stream;

                        _log.WriteLine("Server: attempting to open SslStream.");
                        sslStream.AuthenticateAsServerAsync(certificate, false, _sslProtocols, false).ContinueWith(t => OnAuthenticate(t, state), TaskScheduler.Default);
                    }
                    catch (Exception ex)
                    {
                        _log.WriteLine("Server: Exception: {0}", ex);

                        state.Dispose(); // close connection to client
                    }
                }
                else
                {
                    state = new ClientState(client);

                    // Start listening for data from the client connection
                    try
                    {
                        state.Stream.BeginRead(state.ReceiveBuffer, 0, state.ReceiveBuffer.Length, OnReceive, state);
                    }
                    catch
                    {
                    }
                }
            }

            // Listen for more client connections
            try
            {
                _listener.AcceptTcpClientAsync().ContinueWith(t => OnAccept(t), TaskScheduler.Default);
            }
            catch
            {
            }
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:68,代码来源:DummyTcpServer.cs


注:本文中的ClientState.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。