创建具有SSL一个TCP客户端连接 [英] Creating a TCP Client Connection with SSL
问题描述
我试图建立一个TCP连接并发送/读取使用SSL的数据,但我一直没能成功地做到这一点。
I'm trying to create a TCP connection and send/read data that uses SSL, but I haven't been able to successfully accomplish this.
我倒是喜欢做的是这样的:
What I'd like to do is something like this:
TcpClient _tcpClient = new TcpClient("host", 110);
BinaryReader reader =
new BinaryReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true));
Console.WriteLine(reader.ReadString());
我还没有与任何运气,虽然。创建BinaryReader时抛出一个异常。
I haven't had any luck with it though. An exception is thrown when creating the BinaryReader.
有谁知道一个简单的例子,做这个的?我没有兴趣写这个服务器端,只需在客户端。
Does anyone know of a simple example that does this? I'm not interested in writing the server side of this, just the client.
推荐答案
BinaryReader读取原始数据类型为二进制值在一个特定的编码,是你的服务器发送结果
。如果不使用StreamReader的:
BinaryReader reads primitive data types as binary values in a specific encoding, is that what your server sends?
If not use StreamReader:
TcpClient _tcpClient = new TcpClient("host", 110);
StreamReader reader =
new StreamReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true));
Console.WriteLine(reader.ReadToEnd());
这篇关于创建具有SSL一个TCP客户端连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!