本文整理汇总了C#中SslStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# SslStream.Close方法的具体用法?C# SslStream.Close怎么用?C# SslStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SslStream
的用法示例。
在下文中一共展示了SslStream.Close方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAsyncBasic
public void TestAsyncBasic()
{
var listener = new TcpListener(IPAddress.Loopback, 0);
listener.Start(5);
var ep = (IPEndPoint)listener.LocalEndpoint;
Console.WriteLine("Server> waiting for accept");
listener.BeginAcceptTcpClient((IAsyncResult ar) =>
{
var client = listener.EndAcceptTcpClient(ar);
var sslStream = new SslStream(client.GetStream(), false);
Console.WriteLine("Server> authenticate");
sslStream.BeginAuthenticateAsServer(_ctx.ServerCertificate, async (ar2) =>
{
sslStream.EndAuthenticateAsServer(ar2);
Console.WriteLine("Server> CurrentCipher: {0}", sslStream.Ssl.CurrentCipher.Name);
Assert.AreEqual("AES256-GCM-SHA384", sslStream.Ssl.CurrentCipher.Name);
var buf = new byte[256];
await sslStream.ReadAsync(buf, 0, buf.Length);
Assert.AreEqual(clientMessage.ToString(), buf.ToString());
await sslStream.WriteAsync(serverMessage, 0, serverMessage.Length);
sslStream.Close();
client.Close();
Console.WriteLine("Server> done");
}, null);
}, null);
var evtDone = new AutoResetEvent(false);
var tcp = new TcpClient(AddressFamily.InterNetwork);
tcp.BeginConnect(ep.Address.ToString(), ep.Port, (IAsyncResult ar) =>
{
tcp.EndConnect(ar);
var sslStream = new SslStream(tcp.GetStream());
Console.WriteLine("Client> authenticate");
sslStream.BeginAuthenticateAsClient("localhost", async (ar2) =>
{
sslStream.EndAuthenticateAsClient(ar2);
Console.WriteLine("Client> CurrentCipher: {0}", sslStream.Ssl.CurrentCipher.Name);
Assert.AreEqual("AES256-GCM-SHA384", sslStream.Ssl.CurrentCipher.Name);
await sslStream.WriteAsync(clientMessage, 0, clientMessage.Length);
var buf = new byte[256];
await sslStream.ReadAsync(buf, 0, buf.Length);
Assert.AreEqual(serverMessage.ToString(), buf.ToString());
sslStream.Close();
tcp.Close();
Console.WriteLine("Client> done");
evtDone.Set();
}, null);
}, null);
evtDone.WaitOne();
}