gpt4 book ai didi

c# - 无法从传输连接读取数据 : An existing connection was forcibly closed by the remote host

转载 作者:IT王子 更新时间:2023-10-29 03:38:41 25 4
gpt4 key购买 nike

我有一个服务器应用程序,有时,当客户端尝试连接时,我会收到以下错误:

enter image description here

注意:“无法从客户端获取流或登录失败”是我在 catch 语句中添加的文本

它停止的行(sThread:第 96 行)是:

tcpClient = (TcpClient)client;
clientStream = tcpClient.GetStream();
sr = new StreamReader(clientStream);
sw = new StreamWriter(clientStream);

// line 96:
a = sr.ReadLine();

可能导致此问题的原因是什么?请注意,它不会一直发生

最佳答案

我在调用网络服务时收到此错误。该问题还与传输层安全有关。我可以通过网站项目调用 Web 服务,但是在测试项目中重复使用相同的代码时,我会得到一个包含此消息的 WebException。在调用之前添加以下行解决了问题:

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

编辑

System.Net.ServicePointManager.SecurityProtocol - This property selects the version of the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocol to use for new connections that use the Secure Hypertext Transfer Protocol (HTTPS) scheme only; existing connections are not changed.

我相信 SecurityProtocol 配置在 TLS 握手期间选择协议(protocol)版本时很重要。

TLS handshake - This protocol is used to exchange all the information required by both sides for the exchange of the actual application data by TLS.

ClientHello - A client sends a ClientHello message specifying the highest TLS protocol version it supports ...

ServerHello - The server responds with a ServerHello message, containing the chosen protocol version ... The chosen protocol version should be the highest that both the client and server support. For example, if the client supports TLS version 1.1 and the server supports version 1.2, version 1.1 should be selected; version 1.2 should not be selected.

关于c# - 无法从传输连接读取数据 : An existing connection was forcibly closed by the remote host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5420656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com