2013-04-04 91 views
5

我試圖通過SslStream/Tcp Client連接到服務器。每次我收到一個異常,說明:在AuthenticateAsClient行收到來自傳輸流的意外EOF或0字節。SslStream TcpClient - 從傳輸流接收到意外的EOF或0字節

我已經啓用跟蹤日誌記錄,並讓我在日誌下面的兩個錯誤:

System.Net信息:0:[12260] SecureChannel#66702757 ::構造函數(主機名= xxx.xx.xx .xxx,#clientCertificates = 0,encryptionPolicy = RequireEncryption)

System.Net信息:0:[12260] SecureChannel#66702757 - 留下0個客戶端證書可供選擇。

有人能告訴我如何解決這個問題嗎?不知道爲什麼,但如果這有什麼區別的話,它會拋到外面。

try 
{ 
    TcpClient client = new TcpClient(_host, _port); 
    // _stream = client.GetStream(); 

    _stream = new SslStream(client.GetStream(), false, ValidateServerCertificate, null); 
    _sslReader = new StreamReader(client.GetStream()); 

    try 
    { 
     _stream.AuthenticateAsClient(_host); 
    } 
    catch (AuthenticationException e) 
    { 
     client.Close(); 
     return; 
    } 

    HandleConnect(); 
} 
catch (Exception e) 
{ 
    _logger.Error(e.BuildExceptionInfo()); 
} 

public bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
{ 
    if (sslPolicyErrors == SslPolicyErrors.None || sslPolicyErrors == SslPolicyErrors.RemoteCertificateNameMismatch) 
     return true; 

    return false; 
} 

回答

2

我的猜測是服務器需要客戶端證書。

相關問題