471,313 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,313 software developers and data experts.

How to know when an HTTP page is complete

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,SocketFlag s.None);
TrafficLogTextBox.Text+=Encoding.UTF8.GetString(by tes);
TrafficLogTextBox.Text+="\r\n";
MessageBox.Show(Encoding.UTF8.GetString(bytes));

Nov 26 '05 #1
4 1992
Why don't you use WebClient/WebRequest or any other high level method to
connect to the site?

"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
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,SocketFlag s.None);
TrafficLogTextBox.Text+=Encoding.UTF8.GetString(by tes);
TrafficLogTextBox.Text+="\r\n";
MessageBox.Show(Encoding.UTF8.GetString(bytes));

Nov 26 '05 #2
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.

Nov 27 '05 #3
Nuno Magalhaes wrote:
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,
--
http://www.joergjooss.de
mailto:ne********@joergjooss.de
Nov 27 '05 #4
WRH
Hello
Perhaps something like
while(socket.Receive(bytes,0,socket.Available,Sock etFlags.None) != 0)
with a time out may work
"Nuno Magalhaes" <nu************@hotmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
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,SocketFlag s.None);
TrafficLogTextBox.Text+=Encoding.UTF8.GetString(by tes);
TrafficLogTextBox.Text+="\r\n";
MessageBox.Show(Encoding.UTF8.GetString(bytes));

Nov 27 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Andrew Phillipo | last post: by
6 posts views Thread by Peter Row | last post: by
13 posts views Thread by Davo | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.