异步 HTTP 请求上的 Wince Socket 异常
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异常消息看起来有点误导(“连接尝试失败,因为连接方”),但我认为这意味着您的硬件正在与服务器通信,但服务器没有接受 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.