I have a webrequest that createst a persistent (keepalive) connection to the server, e.g.:
webRequest.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
webRequest.ContentLength = byteArray.Length;
webRequest.Timeout = Timeout.Infinite;
webRequest.KeepAlive = true;
webRequest.ReadWriteTimeout = Timeout.Infinite;
//[System.Threading.Timeout]::Infinite
webRequest.UserAgent = "www.socialblazeapp.com";
Stream dataStream = webRequest.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
webResponse = (HttpWebResponse)webRequest.GetResponse();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
responseStream = new StreamReader(webResponse.GetResponseStream(), encode);
while(!responseStream.EndOfStream){ //do something}
I'm wondering why responseStream.EndOfStream becomes true after a while. I would have assumed that because this is a persistent connection, the stream would never close?
Any ideas why this is happening?