第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

TLS - TCP 客戶端在 SslStream.AuthenticateAsClient

TLS - TCP 客戶端在 SslStream.AuthenticateAsClient

C#
慕尼黑的夜晚無繁華 2022-10-23 16:22:36
我對(duì)網(wǎng)絡(luò)編程相當(dāng)陌生,我需要通過 TLS 連接 TCP 客戶端的幫助。我得到了一個(gè)已經(jīng)編碼的項(xiàng)目,它附帶了證書和提供的公鑰。我已經(jīng)在我的本地機(jī)器上安裝了 pfx 證書,并編寫了一個(gè)指向本地主機(jī)的新 TCP 偵聽器/服務(wù)器和 TCP 客戶端,如下所示:客戶端static void Main(string[] args)    {        string server = "localhost";        TcpClient client = new TcpClient(server, 5997);        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;        //client.Connect(server, 5997);//connection without TLS - authenticating properly        using (SslStream sslStream = new SslStream(client.GetStream(), false,            new RemoteCertificateValidationCallback(ValidateServerCertificate), null))        {            try            {                var servername = "myAuthenticatingServerName";//the server name must be the same as the one on the server certificate                sslStream.AuthenticateAsClient(servername);                try                {                    Console.WriteLine("Client Connected...");                    // Encode a test message into a byte array.                    // Signal the end of the message using the "<EOF>".                    byte[] messsage = Encoding.UTF8.GetBytes("Hello from the client.<EOF>");                    // Send hello message to the server.                     sslStream.Write(messsage);                    sslStream.Flush();                    // Read message from the server.                    string serverMessage = ReadMessage(sslStream);                    Console.WriteLine("Server says: {0}", serverMessage);                    // Close the client connection.                    client.Close();                    Console.WriteLine("Client closed.");                }                catch (Exception e)                {                    Console.WriteLine("Error..... " + e.StackTrace);                }            }     
查看完整描述

1 回答

?
拉莫斯之舞

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超10個(gè)贊

在服務(wù)器端,您正在偵聽端口 8080,在客戶端,您正在連接到端口 5997。更具體地說,您的服務(wù)器正在托管 [YourIP]:8080并且您的客戶端正在嘗試連接到 [YourIP]:5997



此外,Tls 和 SSL 通常用于端口 443??蛻舳撕头?wù)器端口需要相同,以便它們可以相互連接。




也不確定c#是否將'localhost'識(shí)別為'YourIP'最好打開你的cmd(如果你使用的是Windows)輸入'ipconfig'點(diǎn)擊回車并查找并使用你的IPv4地址


查看完整回答
反對(duì) 回復(fù) 2022-10-23
  • 1 回答
  • 0 關(guān)注
  • 190 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)