[英]Creating a TCP Client Connection with SSL
我正在尝试创建TCP连接并发送/读取使用SSL的数据,但我无法成功完成此操作。
我想做的是这样的事情:
TcpClient _tcpClient = new TcpClient("host", 110);
BinaryReader reader =
new BinaryReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true));
Console.WriteLine(reader.ReadString());
我虽然没有运气。 创建BinaryReader时抛出异常。
有谁知道这样做的一个简单例子? 我对写这个服务器端只是客户端不感兴趣。
BinaryReader将原始数据类型读取为特定编码中的二进制值,这是您的服务器发送的内容吗?
如果不使用StreamReader:
TcpClient _tcpClient = new TcpClient("host", 110);
StreamReader reader =
new StreamReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true));
Console.WriteLine(reader.ReadToEnd());
我不完全确定这是否适用于您的应用程序,但我建议您查看stunnel:
http://www.stunnel.org
我过去用它来包装现有的TCP连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.