G
gilad
I am trying to write a program that will send an HTTP request and get an
HTTP response. However, I am having trouble getting the full payload
(i.e. the web page) returned from the host. I am using a blocking
socket, so I need to test the end of the data somehow, or I get a "hung"
effect while the Socket.Receive() method waits.
I constructed a loop like the following to test for end-of-data, but I
only get part of the data returned for large pages and the loop exits.
Socket IPsocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Socket connection code was here...
// The first read takes place...
// ...then the following is executed:
while ( rBytes > 0)
{
if (!IPsocket.Poll(3000,SelectMode.SelectRead))
{
rBytes = IPsocket.Receive(RecvBytes, RecvBytes.Length, 0);
mStrm.Write(RecvBytes,0,rBytes);
break;
}
rBytes = IPsocket.Receive(RecvBytes, RecvBytes.Length, 0);
// Write to buffer
mStrm.Write(RecvBytes,0,rBytes);
}
Is there different way I should be testing for the end of the data? I've
tried using Socket.Available(), but found that it returns 0 when there
is in fact more data.
Thanks, JA
HTTP response. However, I am having trouble getting the full payload
(i.e. the web page) returned from the host. I am using a blocking
socket, so I need to test the end of the data somehow, or I get a "hung"
effect while the Socket.Receive() method waits.
I constructed a loop like the following to test for end-of-data, but I
only get part of the data returned for large pages and the loop exits.
Socket IPsocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Socket connection code was here...
// The first read takes place...
// ...then the following is executed:
while ( rBytes > 0)
{
if (!IPsocket.Poll(3000,SelectMode.SelectRead))
{
rBytes = IPsocket.Receive(RecvBytes, RecvBytes.Length, 0);
mStrm.Write(RecvBytes,0,rBytes);
break;
}
rBytes = IPsocket.Receive(RecvBytes, RecvBytes.Length, 0);
// Write to buffer
mStrm.Write(RecvBytes,0,rBytes);
}
Is there different way I should be testing for the end of the data? I've
tried using Socket.Available(), but found that it returns 0 when there
is in fact more data.
Thanks, JA