I am making a program that sends a file to a socket, and gets a response.
I have been able so far to write in the socket, but when I get to the GetResponse() line, the program hangs indefinitively.
Here’s the code:
public void ConexionSocket()
{
try
{
FileStream fileStream = System.IO.File.OpenRead(@”C:\DIS.xml”);
byte[] byData2 = new byte[fileStream.Length];
fileStream.Read(byData2, 0, byData2.Length);
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(“http://1.1.1.1:28903″);
myHttpWebRequest.Method = “POST”;
myHttpWebRequest.SendChunked = true;
myHttpWebRequest.ContentLength = byData2.Length;
myHttpWebRequest.ContentType = @”application/x-www-form-urlencoded”;
myHttpWebRequest.AllowWriteStreamBuffering = true;
myHttpWebRequest.Accept = “text/plain”;
myHttpWebRequest.ProtocolVersion = HttpVersion.Version10;
myHttpWebRequest.KeepAlive = false;
System.IO.Stream os = myHttpWebRequest.GetRequestStream();
os.Write(byData2, 0, byData2.Length);
os.Flush();
//The program hangs when entering this line
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
Stream streamResponse = myHttpWebResponse.GetResponseStream();
StreamReader streamRead = new StreamReader(streamResponse);
Char[] readBuff = new Char[256];
int count = streamRead.Read(readBuff, 0, 256);
String strResultado = string.Empty;
}
catch (InvalidOperationException ioe)
{
throw ioe;
}
catch (Exception ex)
{
throw ex;
}
}
If I close the os instance after the Flush, then I get a “Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.” exception.
Any suggestions to this?
This is driving me crazy, really, as it hasn’t been an answer over the Internet so far that has worked for me.



November 25th, 2008 at 3:58 pm
I’m stating the obvious, but are you sure that a response has been sent to you? Because otherwise being a blocking call, it WILL wait for one FOREVER.
A way to check that is to do the same using a web browser, or looking at incoming packet on your firewall.