Valid internet connection

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
I have a loop which performs some operations. Ive noticed if the internet connection is broken the loop continues but the operation fails.
The entire code is based on HttpRequest and Response.

What i would like is a way to trap if a valid connection is not available INSIDE the loop without having any performance penalties?

Any advice?

Thanks
 
Thanks everyone. I managed to catch an exception on the line

Bytes = str.Read(buff, 0, BufferByte.Length)

and get the error:

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

The reason why this happened was i deliberately resetted the ineternet connection. Just so everyone is clear, all im trying to do is download a file, if the internet connection drops resume it from where the downloading stopped (or app crashed).

I tried to reset the str (Stream) variable and attempt the operation again but i get the same or similar error. Is it possible to handle this error so that it starts the process again from where it left it (or at least get past this error and then i guess i could continue)?
 
Last edited:
in general "Forcibly closed by the remote host" usually points to a port that isn't open or listening, Does the program Start to download then you get the error or the not download at all then error?
 
When i download the file, its within the loop. I reset the connection and the loop returns the error above.

At this point everytime it tries to execute the line

Bytes = str.Read(buff, 0, BufferByte.Length)

Its falls into the Try Catch block and reports the above error. The internet connection is backup now and although i get the same error i do occasionally get a series of errors:

The operation has timed out. (I know i can increase the time out period so not too concerned about this error)
A connection attempt failed because the connected party did not properly respond after a period of time

All of which seem to crash at the line above and i cant get it going again?

Thanks
 
make sure the path to the file exsist's, weather it be "http://www.somsite.com/File.Bla", once you have detrmined this then proceed to you code and check their that the Right host and file path chosen is correct, to me the Programs throwing the exception due to the file not being downloaded, just a thought?.
 
The file definately exists. I checked the path in my webRequest and its the same.

I have now reset the fileStream and Stream variables. The error i get when trying to download (whilst inside the loop) and after resetting the internet connection is "Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.", in case this makes any difference.

Welcome to any further ideas :-(.
 
hmmm Maybe the loop is causing the error, do you think its trying to d/l the same file mutiple times or have you handled this correctly so it does not? try to make multiple connections to the remote file?.
 
Ill double check to see if its handling multiple files correctly.

I tried using WebClient which started to work but i cant extend the timeout property as one doesnt exist. Im not sure if it supports redownloading from where the connection broke but i noticed the timeout error popped up and deleted the file. Ill have a read up on that class however feel free to post any other workarounds if any. Thanks
 
Another point i thought to add. When the file is being downloaded and the connection drops, if the connection is back up in under 20 seconds, the downloading continues. Any longer than that then either i get one of the errors from before or i get timeout errors.

So to me it seems the server is refusing the connection after 20 seconds? So two ways out of this possibly:

1. Using Httpwebrequest my guess is to try and redownload by passing in the current byte to start from if a file exists to the FileStream? Thus starting everything right from the start.
2. Using WebClient, ive not managed to find any reference on how to resume the download?
 
Back
Top