2008-10-31 113 views
11

我正在嘗試創建TCP連接併發送/讀取使用SSL的數據,但我無法成功完成此操作。使用SSL創建TCP客戶端連接

我希望做的是這樣的:

TcpClient _tcpClient = new TcpClient("host", 110); 

    BinaryReader reader = 
     new BinaryReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true)); 

    Console.WriteLine(reader.ReadString()); 

我沒有任何運氣與它雖然。創建BinaryReader時引發異常。

有沒有人知道一個簡單的例子,這樣做?我不想寫這個服務器端,只是客戶端。

+0

BinaryReder一個特定編碼讀取原始數據類型爲二進制值,是你的服務器發送? – 2008-10-31 01:37:11

回答

12

BinaryReader將原始數據類型讀取爲特定編碼中的二進制值,請問您的服務器發送了什麼?
如果不使用的StreamReader:

TcpClient _tcpClient = new TcpClient("host", 110); 

StreamReader reader = 
    new StreamReader(new System.Net.Security.SslStream(_tcpClient.GetStream(), true)); 

Console.WriteLine(reader.ReadToEnd()); 
1

我不能完全肯定這是否會爲你的應用程序工作,但我會建議考慮看看安全通道:
http://www.stunnel.org

我用它在過去包裝現有的TCP連接。