c# - 使用 SSL 创建 TCP 客户端连接

标签 c# .net ssl tcp

我正在尝试创建一个 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());

关于c# - 使用 SSL 创建 TCP 客户端连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/252365/

相关文章:

c# - 用于实体更改跟踪的 Asp.net 事件

.net - Linq2XSD 死了吗?

java - 使用 ssl : sending certificate file from client 的服务器端身份验证

java - 通过 SSL 的 SOAP 网络服务连接

c# - 单卡怎么拖

c# - 如何使用带进度条的 ASP.NET MVC4 Web Api 上传大文件

.net - Azure构建管道: How to include additional project in artifact?

ssl - href 方案不断从 http 更改为 https

c# - public {get;之间的区别set} 和编程 getter 和 setter

java - 建议将什么逻辑放入存储过程中?