使用 SSL 创建 TCP 客户端连接 [英] Creating a TCP Client Connection with SSL

查看:43
本文介绍了使用 SSL 创建 TCP 客户端连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建 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.

我想做的是这样的:

    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆