将SslStream与IOCP结合使用 [英] Using SslStream with IOCP

查看:125
本文介绍了将SslStream与IOCP结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Socket类的异步/ IOCP方法BeginSend()/ BeginRead()/ etc等编写了TCP服务器。我想使用SslStream添加SSL功能,但是从接口上看,Socket和SslStream似乎不打算一起工作,尤其是因为我根本不使用Streams,并且SslStream似乎依赖于Stream来工作。 。

I have written a TCP server using the Socket class's asynchronous/IOCP methods, BeginSend()/BeginRead()/etc. I would like to add SSL capability using SslStream, but from the interface it looks like Socket and SslStream are not intended to work together, in particular because I'm not using Streams at all and SslStream appears to depend on having a Stream to work with.

这可能吗,还是我看错地方了?我是否需要构造自己的Stream子类并将其输入到我的Socket实例中,并指向SslStream?对我来说,重要的是我的服务器出于扩展方面的考虑而使用IOCP。

Is this possible, or am I looking in the wrong place? Do I need to fashion my own Stream subclass that feeds into my Socket instances and point SslStream at that? It's important to me that my server use IOCP due to scaling concerns.

推荐答案

将套接字包装在 NetworkStream 到与 SslStream 一起使用。

Wrap your Socket in a NetworkStream to use it with an SslStream.

Socket socket;
...
using (var networkStream = new NetworkStream(socket, true))
using (var sslStream = new SslStream(networkStream, ...))
{
   // use sslStream.BeginRead/BeginWrite here
}

流公开BeginRead / BeginWrite方法,所以您不要松开这方面。

Streams expose BeginRead/BeginWrite methods as well, so you don't loose this aspect.

这篇关于将SslStream与IOCP结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆