Re: HTTP ping pong



Roedy Green wrote:
Over time I have been learning how browsers and servers talk to each
other.

It seems to work like this:

Your browsers sets a GET or POST.

The server responds with web page.

In the web page are a number of images.

the browser then simultaneously sends some more get requests. I think
each one gets its own socket. data seems to flow back simultaneously
(interleaved packets).

Sometimes there is a redirect. I think it is normally up to the
browser to request the next leg and wait for the response. Other
times the server can handle the redirect itself and send something
with a note in the header where the new home is.

There are two flavours of redirect, temporary and permanent. Temporary
ones are used for load balancing, redirecting to a backup server etc.
Permanent ones the server wants to you note, and use the new URL
instead. Temporary redirects will likely soon point nowhere.

There are a couple of things I have not yet figured out.

1. If I login for example sometimes I see a page on the browser, then
that page is replaced by another page a few seconds like. I did not
touch the keyboard. What happened?

2. Does the sever ever send more than one response to the same
request?

3. How do popups work. How can a server send you something you did not
request?

4. At the Java HTTP level, does do you know when you have hit the end
of the data? an EOF exception or something else?


As you might guess, I am feeling an urge to write a little essay
called HTTP ping pong.

The client (browser) sends the server a request i.e. "give me this" or "here is some data for you" or a combination of the two. The server sends back a response. One response per request. If the request was for a web page, back comes HTML.

Included in the HTML can be arguments for images. As the browser comes across img arguments it sends a request to the server for the image data. Multiple streams can be (usually are) opened, one per image. In other words, multiple requests and multiple responses but still one for one.

JavaScript may also be included within the HTML. Popups and redirects are usually done with JS. While the JS library pales next to Java, there are a fair amount of methods that are available (wait five seconds then redirect, open new window, etc. all can be done with built in methods), cheat sheets here: http://www.addedbytes.com/cheat-sheets/javascript-cheat-sheet/

Unless you're looking to write a server, EOF data would be pretty much under the hood for an app running in a container (Tomcat, JBoss, etc.). File transfer in HTTP is a loose construct between the server (Apache, Tomcat, etc.) and the browser which should be set via a Content-Length header. When the bytes received equals the bytes claimed, the browser assumes EOF. Header definitions here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

--
Dave Miller
Java Web Hosting
http://www.cheap-jsp-hosting.com/
.


Loading