gpt4 book ai didi

c# - System.Net.Sockets.SocketException 灾难

转载 作者:行者123 更新时间:2023-12-03 12:05:26 26 4
gpt4 key购买 nike

在我们与业务层断开连接并通过 MVC Web API 进行通信的 Winforms 客户端应用程序中,我们收到了一个严重的错误。哪位高手能解释一下!
这是什么意思呢?

---> (Inner Exception #0) System.Net.Http.Httprequestexception: An Error Occurred While Sending The Request.
---> System.Net.Webexception: The Underlying Connection Was Closed: An Unexpected Error Occurred On A Receive.
---> System.Io.Ioexception: Unable To Read Data From The Transport Connection: An Existing Connection Was Forcibly Closed By The Remote Host.
---> System.Net.Sockets.Socketexception: An Existing Connection Was Forcibly Closed By The Remote Host
At System.Net.Sockets.Socket.Endreceive(Iasyncresult Asyncresult)
At System.Net.Sockets.Networkstream.Endread(Iasyncresult Asyncresult)
--- End Of Inner Exception Stack Trace ---
At System.Net.Sockets.Networkstream.Endread(Iasyncresult Asyncresult)
At System.Net.Pooledstream.Endread(Iasyncresult Asyncresult)
At System.Net.Connection.Readcallback(Iasyncresult Asyncresult)
--- End Of Inner Exception Stack Trace ---
At System.Net.Httpwebrequest.Endgetresponse(Iasyncresult Asyncresult)
At System.Net.Http.Httpclienthandler.Getresponsecallback(Iasyncresult Ar)
--- End Of Inner Exception Stack Trace ---<---

最佳答案

好吧,总的来说,这个异常(exception)确实非常令人烦恼。但是你有什么期望?您正在使用网络。它经常躺下并起床。这种行为有两个主要原因:

  • 执行代码的网络质量。
  • 程序员在实现自己的通信协议(protocol)时所犯的错误。

  • 如果这两个原因不存在,那么您应该使用超时实现自动连接之类的东西。此外,TCP 协议(protocol)实现内部将非常有帮助!

    关于c# - System.Net.Sockets.SocketException 灾难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21295701/

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