C# 使用SSL创建TCP客户端连接
我正在尝试创建一个TCP连接,并使用SSL发送/读取数据,但我还未能成功完成这项工作 我想做的是这样的:C# 使用SSL创建TCP客户端连接,c#,.net,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(r
TcpClient _tcpClient = new TcpClient("host", 110);
BinaryReader reader =
new BinaryReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true));
Console.WriteLine(reader.ReadString());
不过,我的运气不好。创建BinaryReader时引发异常
有人知道这样一个简单的例子吗?我对编写服务器端不感兴趣,只对客户端感兴趣。我不完全确定这是否适用于您的应用程序,但我建议您看看stunnel:
我过去曾使用它包装现有的TCP连接。BinaryReader以特定编码将原始数据类型读取为二进制值,这就是您的服务器发送的吗?
如果不使用StreamReader:
TcpClient _tcpClient = new TcpClient("host", 110);
StreamReader reader =
new StreamReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true));
Console.WriteLine(reader.ReadToEnd());
BinaryReder以特定编码将原始数据类型读取为二进制值,这是您的服务器发送的吗?请发布异常文本。