I am developing C# clent/server application based on two windows serv开发者_如何学Goices, which are set up on a clients(.NET 2) machine and windows server 2003.
Sometimes I get an exception
Unable to read data from the transport connection. An existing connection was forcibly closed by the remote host
It doesn't happen at a constant period in time. From service restart on the server, it takes sometimes 2 weeks or even just 1 day until the exception begins to occur.
How do I correct this problem?
Thanks
Sounds like intermittent network problems. It's quite common in wireless networks, and it can also happen on wired networks from time to time (Ethernet is not a deterministic protocol). The reasons can be various. However, in addition to fixing your network problems, I would strongly recommend to make your service resilient against network problems.
(Think about the simple case that someone unplugs the server's network cable for a short moment: If your application crashes with an unhandled exception, administrator intervention is required to get it running again. You don't want that. That's not good behaviour for a service.)
Thus, your service should catch IO exceptions, make an entry into the Windows application log and retry the operation a little bit later (to avoid flooding the event log or putting unnecessary load on the machine or the network).
精彩评论