How to know when an HTTP page is complete

N

Nuno Magalhaes

I'm doing a "low level" server with sockets and trying to read the HTTP
data from server.
socket.Available at the beginning is 0 and I don't know when an HTTP
page is completly read since socket.Available sometimes is 0 and the
pages don't return the Content-Length field in the HTTP header.

How can I know when an HTTP page is complete? How does Internet
Explorer or Mozilla Firefox implements this procedure?

Any hints? Here's my simple code to retrieve the data after I connect
to the server:

**************************************************
byte[] msg=Encoding.UTF8.GetBytes("GET / HTTP/1.1\n\n");
byte[] bytes=new byte[65536];
int i=socket.Send(msg,0,msg.Length,SocketFlags.None);
MessageBox.Show("Sent "+i.ToString()+" bytes. Available:
"+socket.Available.ToString()+" bytes.");
socket.Receive(bytes,0,socket.Available,SocketFlags.None);
TrafficLogTextBox.Text+=Encoding.UTF8.GetString(bytes);
TrafficLogTextBox.Text+="\r\n";
MessageBox.Show(Encoding.UTF8.GetString(bytes));
 
L

Lebesgue

Why don't you use WebClient/WebRequest or any other high level method to
connect to the site?
 
N

Nuno Magalhaes

Because I'm doing a project that consists on logging certain parameters
of QoS as Time to Resolve DNS, Time To Connect, Time To Receive Data,
etc...

Any hints on how can I know if a web page is complete (note: I don't
always get the content-length parameter in the response header).

How does IE or Mozilla implements this procedure... how does it know
when a page is completly read?

Thank for any reply,
Nuno Magalhaes.
 
J

Joerg Jooss

Nuno said:
Because I'm doing a project that consists on logging certain
parameters of QoS as Time to Resolve DNS, Time To Connect, Time To
Receive Data, etc...

Any hints on how can I know if a web page is complete (note: I don't
always get the content-length parameter in the response header).

How does IE or Mozilla implements this procedure... how does it know
when a page is completly read?

Read the spec: http://www.w3.org/Protocols/rfc2616/rfc2616.html.

Cheers,
 
W

WRH

Hello
Perhaps something like
while(socket.Receive(bytes,0,socket.Available,SocketFlags.None) != 0)
with a time out may work
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top