Code
WebRequest and Unable to read data from the transport connection Error
Weird thing just happened, a Windows Service responsible for grabbing some data form an online XML source, suddenly stopped working after two years of continuous functioning…
First I thought that the remote XML had changed somehow but the service returned
“Unable to read data from the transport connection: The connection was closed.”
The code that connected to the remote XML was pretty low-tech:
WebRequest wRq = WebRequest.Create(remoteUri);
WebResponse wRs = wRq.GetResponse();
Stream strm = wRs.GetResponseStream();
StreamReader sr = new StreamReader(strm, Encoding.UTF7);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(strm); //IT WAS CRASHING HERE
After some research it seems that the remote side closes the connection prior to it being finished…
I had to change the code as follows and the problem was solved:
CookieContainer CC = new CookieContainer();
HttpWebRequest wRq = (HttpWebRequest)WebRequest.Create(remoteUri);
wRq.Proxy = null;
wRq.UseDefaultCredentials = true;
wRq.KeepAlive = false; //THIS DOES THE TRICK
wRq.ProtocolVersion = HttpVersion.Version10; // THIS DOES THE TRICK
wRq.CookieContainer = CC;
WebResponse wRs = wRq.GetResponse();
Stream strm = wRs.GetResponseStream();
StreamReader sr = new StreamReader(strm, Encoding.UTF7);
XmlDocument xDoc = new XmlDocument();
xDoc.Load(strm); //NO LONGER CRASHING HERE
True randomness
Ok…how random is randomize() ?
What’s to make a computer generate a random number? Well we’ve got the physical way and the math way.
1. Physical (True random). Implement a hash function on to an unpredictable video frame… have a camera pointed at the sky, a lava lamp , listening to atmospheric noise
2. Mathematical. (Pseudeo random). Recurrencial http://en.wikipedia.org/wiki/Linear_congruential_generator or variations…using the bios time clock as seed.
Anyway if you’re looking for true randomness take a look at www.random.org
Categories
Archive
- September 2009
- August 2009
- July 2009
- June 2009
- January 2009
- October 2008
- September 2008
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Links
- Iluminis
- Synaptic Solutions
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 947
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/code4b/public_html/sysrc/wp-includes/kses.php on line 948