• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2240
  • Last Modified:

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

A TCPClient hit the following exception:

ExceptionMessage: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
StackTrace:    at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at System.IO.StreamReader.ReadBuffer()
   at System.IO.StreamReader.ReadLine()
   at Gateway.Dispatcher.ServiceAgent.BillingAgent.SendBilling(String xml)
Source: System

This is the code for the TCPClient :
               client = new TcpClient(serverIP, port);
                stream = client.GetStream();
                writer = new StreamWriter(stream);
                reader = new StreamReader(stream);
                writer.WriteLine(xml);
                writer.Flush();
                responseData = reader.ReadLine();
 
                reader.Close();
                stream.Close();
                client.Close();

Problem occur intermittently.
Any idea?
0
mkdev2009
Asked:
mkdev2009
  • 2
1 Solution
 
Alan WarrenCommented:
"An existing connection was forcibly closed by the remote host" is an error I have encountered when attempting to download large ms access db files from an FTP location over a very slow connection. The error is raised on FTP timeout.

Possibly this line:
   stream = client.GetStream(); is timing out.

Alan
0
 
mkdev2009Author Commented:
Hi Alan, Thanks for the reply.
Any recommend solution on this ?
0
 
Alan WarrenCommented:
Hi mkdev2009,
unsure if we are dealing with a web site/application here, but if so, some suggest that increasing the <system.web><httpRuntime maxRequestLength="1048576" executionTimeout="300" in the web.config is the go.

"Intermittent Errors" are a pain, because you can apply the patch, but only time will tell if you have a solution.

Alan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now