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


C# SslStream.?.Dispose方法代码示例

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


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

示例1: CreateSslHandler

		private async void CreateSslHandler(Stream socket, X509Certificate2 certificate)
		{
			SslStream ssl = null;
			try
			{
				ssl = new SslStream(socket, false, SslRemoteCertificateValidateCallback, null);
				
				await ssl.AuthenticateAsServerAsync(serverCertificate, clientCertificateRequired, sslProtocols, false); // no revocation

				var protocol = this.GetService<OdetteFileTransferProtocolItem>(true);
				await protocol.StartProtocolAsync(new OdetteNetworkStream(ssl, "ssl:" + serverTcp.GetStreamInfo(socket), Config), false);
			}
			catch (Exception e)
			{
				Log.Except("Protocol initialization failed.", e);
				ssl?.Dispose();
			}
		} // func CreateSslHandler
开发者ID:twdes,项目名称:odette,代码行数:18,代码来源:OdetteListenerTcp.cs

示例2: _sockConnection


//.........这里部分代码省略.........
                        {
                            DebugEx.Assert("Not authenticated");
                            throw new Exception("Not authenticated");
                        }
                        if (!sslstream.IsEncrypted)
                        {
                            DebugEx.Assert("No encryption");
                            throw new Exception("Not encryption");
                        }

                        //get info
                        isSecured = true;
                        sslProtocol = sslstream.SslProtocol.ToStringInvariant();

                        //use this stream from now on
                        _netstream = sslstream;
#elif UNIVERSAL
                        _sock.UpgradeToSslAsync(SocketProtectionLevel.Tls12, new Windows.Networking.HostName(remCertHostName)).AsTask().Wait();
                        var _isSecured = _sock.Information.ProtectionLevel == SocketProtectionLevel.Tls10 ||
                                     _sock.Information.ProtectionLevel == SocketProtectionLevel.Tls11 ||
                                     _sock.Information.ProtectionLevel == SocketProtectionLevel.Tls12;
                        if (!_isSecured)
                            throw new Exception("Connection not secured (" + _sock.Information.ProtectionLevel + ")");
#endif
                    }
                    catch (Exception ex)
                    {
                        DebugEx.TraceError(ex, "Certificate not accepted, " + ex.Message);
                        result.Message = "Certificate not accepted, " + ex.Message;
                        if (ex.InnerException != null)
                            result.Message += "  (inner msg=" + ex.InnerException.Message + ")";
                        try { Close("Certificate not accepted, " + ex.Message); } catch { }
#if NETFX
                        try { _netstream?.Close(); _netstream?.Dispose(); } catch { }
                        try { sslstream?.Close(); sslstream?.Dispose(); } catch { }
                        try { _sock?.Close(); } catch { }
#endif
                        try { _sock?.Dispose(); } catch { }
                        return result;
                    }
                }


                //write packers
#if NETFX
                var _nodelay = _sock.NoDelay;
                _sock.NoDelay = true; //Disable the Nagle Algorithm
                _netstream.WriteByte((byte)this.SupportedChannelSerializationModes);
                _netstream.WriteByte((byte)this.PreferredChannelSerializationModes);
                _sock.NoDelay = _nodelay; //Restore (default:enable) the Nagle Algorithm
#elif UNIVERSAL
                {
                    var wStream = _sock.OutputStream.AsStreamForWrite();
                    wStream.WriteByte((byte)this.SupportedChannelSerializationModes);
                    wStream.WriteByte((byte)this.PreferredChannelSerializationModes);
                    wStream.Flush();
                }
#endif

                //read final packer
                var packerType = ChannelSerializationMode.Unkown;
#if NETFX
                packerType = (ChannelSerializationMode)_netstream.ReadByte();
#elif UNIVERSAL
                packerType = (ChannelSerializationMode)_sock.InputStream.AsStreamForRead().ReadByte();
#endif
开发者ID:yodiwo,项目名称:plegma,代码行数:67,代码来源:Client.cs


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