[英]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.