异步 HTTP 请求上的 Wince Socket 异常

发布于 2024-12-05 23:59:50 字数 932 浏览 2 评论 0原文

我正在用 C# 编写一个 WinCE 应用程序,该应用程序向驻留在我的网络上的 APACHE 服务器发出 HTTP POST。由于一些网络问题(我猜测),我在托管代码中收到以下异常。

System.Net.Sockets.SocketException occurred
    Message="A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"
    ErrorCode=10060  
    NativeErrorCode=10060
    StackTrace:
       at System.Net.Sockets.Socket.ConnectNoCheck(EndPoint remoteEP)
       at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
       at System.Net.Connection.doConnect(IPEndPoint ep)
       at System.Net.Connection.connect(Object ignored)
       at System.Threading.ThreadPool.WorkItem.doWork(Object o)
       at System.Threading.Timer.ring()

此异常并不总是抛出,但当抛出时,我的应用程序根本无法连接到服务器。重复的连接尝试也无助于重新连接。唯一有帮助的是关闭并重新部署应用程序。

我无法捕获异常,因为它位于托管代码内部。有什么方法可以绕过这个问题并关闭与我的服务器的所有套接字连接并重新初始化它们?我做错了什么吗?

I am writing a WinCE app in C# that makes an HTTP POST to an APACHE server residing on my network. Because of some network issues (I am guessing), I get the following exception in the managed code

System.Net.Sockets.SocketException occurred
    Message="A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"
    ErrorCode=10060  
    NativeErrorCode=10060
    StackTrace:
       at System.Net.Sockets.Socket.ConnectNoCheck(EndPoint remoteEP)
       at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
       at System.Net.Connection.doConnect(IPEndPoint ep)
       at System.Net.Connection.connect(Object ignored)
       at System.Threading.ThreadPool.WorkItem.doWork(Object o)
       at System.Threading.Timer.ring()

This exception isn't always thrown, but when it is thrown, my app fails to connect to the server AT ALL. Repeated connection attempts don't help in reconnecting either. The only thing that helps is closing and re-deploying the app.

I can't catch the exception because its inside of managed code. Is there any way to circumvent this and close all socket connections to my server and re-initialize them? Is there something I am doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

脱离于你 2024-12-12 23:59:50

异常消息看起来有点误导(“连接尝试失败,因为连接方”),但我认为这意味着您的硬件正在与服务器通信,但服务器没有接受 TCP 级别的连接。

我能想到的一个问题是“挂起”连接,导致服务器达到最大并发连接数并停止接受新连接。

虽然这只是一个猜测,但如果可以的话,您可能需要检查 apache 日志,看看是否可以找出服务器是否报告了任何内容,并且也许在问题再次出现时尝试重新启动 apache。如果这有帮助,当然你仍然需要找到原因。

The exception message looks a bit misleading ("connection attempt failed because the connected party") but I think it means your hardware is communicating with the server, but the server is not accepting the connection on the TCP level.

A problem I could think of is "hanging" connections, causing the server to reach the maximum number of concurrent connections and to stop accepting new ones.

Although it's just a guess, you might want to check the apache log if you can to see if you can find out if the server reports anything, and perhaps try restarting apache as soon as the problem occurs again. If that helps, you still need to find the cause of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文