Jamie
Jamie

Reputation: 779

System.Net.Sockets.SocketException Disaster

In our Winforms client app that is disconnected from the business layer and communicates via MVC web API, we get a nasty error. Are there any experts out there who can please explain!

What does all this mean?

---> (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 ---<---

Upvotes: 1

Views: 3659

Answers (1)

EngineerSpock
EngineerSpock

Reputation: 2675

Well, in general, this exception is very vexing, indeed. But what you have expected? You are working with the network. It lies down and gets up frequently. There are two main reasons of such a behaviour:

  1. The quality of the network in which the code is executing.
  2. Errors made by programmers if they implemented their own protocol of communication.

If these two reasons are not in place, then you should implement something like auto connection using timeouts. Also, the TCP-protocol implemetation internals will be very helpful!

Upvotes: 1

Related Questions