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?
mkdev2009Asked:
Who is Participating?
 
Alan WarrenConnect With a Mentor Applications DeveloperCommented:
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
 
Alan WarrenApplications DeveloperCommented:
"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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.