Using SslStream with IOCP

前端 未结 1 1600
春和景丽
春和景丽 2021-01-24 14:51

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 i

1条回答
  •  抹茶落季
    2021-01-24 15:37

    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
    }
    

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

    0 讨论(0)
提交回复
热议问题