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

Posted on 2012-09-02
Last Modified: 2012-09-24
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);
                responseData = reader.ReadLine();

Problem occur intermittently.
Any idea?
Question by:mkdev2009
    LVL 26

    Expert Comment

    by:Alan Warren
    "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.


    Author Comment

    Hi Alan, Thanks for the reply.
    Any recommend solution on this ?
    LVL 26

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now