473,385 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to fix error: Unable to read data from the transport connection

I encountered the above error and don't know how to fix it or set the timer. Anyone please help.

Here is my code for the background thread:

Expand|Select|Wrap|Line Numbers
  1. private BackgroundWorker _backgroundWorker = null;
  2. Stream strResponse;
  3. Stream strLocal;
  4. HttpWebRequest webRequest;
  5. HttpWebResponse webResponse;
  6. bool goPause = false;
  7.  
  8.  
  9. private void btnDownload_Click(object sender, EventArgs e)
  10. {
  11.     // Let the user know we are connecting to the server
  12.     lblProgress.Text = "Download Starting";
  13.     long startPoint = 0;
  14.  
  15.     if (File.Exists(txtPath.Text))
  16.         startPoint = new FileInfo(txtPath.Text).Length;
  17.  
  18.     int startPointInt = Convert.ToInt32(startPoint);
  19.  
  20.     List<Object> arguments = new List<Object>();
  21.     arguments.Add(TxtURL.Text);
  22.     arguments.Add(txtPath.Text);
  23.     arguments.Add(startPointInt);
  24.  
  25.     _backgroundWorker = CreateWorker();
  26.     _backgroundWorker.RunWorkerAsync(arguments);
  27.  
  28. }
  29.  
  30. public BackgroundWorker CreateWorker()
  31. {
  32.     BackgroundWorker bg = new BackgroundWorker();
  33.     bg.WorkerSupportsCancellation = true;
  34.     bg.DoWork += DoWork;
  35.     return bg;
  36. }
  37.  
  38. private void DoWork(Object sender, DoWorkEventArgs e)
  39. {
  40.     List<Object> arguments = (List<Object>)e.Argument;
  41.     try
  42.     {
  43.         int startPointInt = Convert.ToInt32(arguments[2]);
  44.  
  45.         // Create a request to the file we are downloading
  46.         webRequest = (HttpWebRequest)WebRequest.Create((String)arguments[0]);
  47.  
  48.          webRequest.AddRange(startPointInt);
  49.  
  50.          webRequest.Credentials =CredentialCache.DefaultCredentials;
  51.  
  52.          // Retrieve the response from the server
  53.          webResponse = (HttpWebResponse)webRequest.GetResponse();
  54.  
  55.           Int64 fileSize = webResponse.ContentLength;
  56.  
  57.           strResponse = webResponse.GetResponseStream();
  58.  
  59.           if (startPointInt == 0)
  60.           {
  61.               strLocal = new FileStream((String)arguments[1], FileMode.Create, FileAccess.Write, FileShare.None);
  62.            }
  63.            else
  64.            {
  65.               strLocal = new FileStream((String)arguments[1], FileMode.Append, FileAccess.Write, FileShare.None);
  66.            }
  67.  
  68.             int bytesSize = 0;
  69.  
  70.             byte[] downBuffer = new byte[2048];
  71.  
  72.             while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
  73.             {
  74.                 strLocal.Write(downBuffer, 0, bytesSize);
  75.  
  76.                  if (goPause)
  77.                      break;
  78.              }
  79.             }
  80.             finally
  81.             {
  82.                 goPause = false;
  83.  
  84.                 if (webRequest != null)
  85.                     webRequest = null;
  86.                 if (webResponse != null)
  87.                     webResponse.Close();
  88.                 if (strResponse != null)                
  89.                     strResponse.Close();
  90.                 if (strLocal != null)
  91.                     strLocal.Close();                
  92.             }
  93.         }
  94. }
  95.  
  96. private void btnStop_Click(object sender, EventArgs e)
  97. {
  98.    // Close the web response and the streams
  99.    if (webResponse != null)
  100.    {
  101.         goPause = true;
  102.  
  103.         _backgroundWorker.CancelAsync();
  104.  
  105.         webResponse.Close();
  106.         strResponse.Close();
  107.         strLocal.Close();
  108.     }
  109. }
  110.  
Nov 4 '10 #1
0 1513

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mike Dole | last post by:
I'm working on a client - server application based on the 'How to Sockets Server and How to Sockets Client' code from the Visual Basic ..NET Resource Kit. Since I want to be able to send 'big...
0
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two...
1
by: Muscha | last post by:
Hello, Every now and then my application throw this exception: "Unable to read data from the transport connection" And when I break into the Visual Studio, the thread where it failed has...
0
by: Aryeh Holzer | last post by:
Hi, I've been trying to use the weather webservice available from the National Weather Service (NWS), at http://www.nws.noaa.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML. wsdl without success. Here's...
0
by: Brent | last post by:
After six months flawless operation, I'm suddenly getting this error: "Unable to read data from the transport connection." The code* hasn't changed, and from what I can see, neither have the IP...
0
by: Arno | last post by:
Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with...
1
by: Terrance | last post by:
I'm trying to create a small messenger program that uses the tcpclient and tcplistenter objects. When I start the application and run the thread that fires the tcplistener; once the client sends...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
6
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.