An Exploration of Dynamic Documents

来源:百度文库 编辑:神马文学网 时间:2024/04/29 07:37:03
ANEXPLORATION OFDYNAMICDOCUMENTS
INTRODUCTION
This document explores the "server push" and "client pull" dynamicdocument capabilities of Netscape Navigator 1.1 (Windows, Mac, andUnix versions). Please send comments topushpull@netscape.com.Also, if you are using either server push or client pull in areal-world application, please drop us a note atpushpull@netscape.comand let us know -- thanks!
Examples are given at the end, along with an important note onimplementing server push CGI programs as shell scripts.
THEGREATIDEA
The general idea is that browsers have always been driven by userinput. You click on a link or an icon or an image and some data comesto you. As soon as people saw they could do that, they wanted to givea server the ability to push new data down to the browser. (Anobvious example is a stock trader who wants to see new quote dataevery 5 minutes.) Up until now, that hasn‘t been possible.
Netscape Navigator 1.1 gives content creators and serveradministrators two new open standards-based mechanisms for making thiswork. The mechanisms are similar in nature and effect, butcomplementary. They are:
Server push -- the server sends down a chunk of data; the browser display the data but leaves the connection open; whenever the server wants it sends more data and the browser displays it, leaving the connection open; at some later time the server sends down yet more data and the browser displays it; etc.
Client pull -- the server sends down a chunk of data, including a directive (in the HTTP response or the document header) that says "reload this data in 5 seconds", or "go load this other URL in 10 seconds". After the specified amount of time has elapsed, the client does what it was told -- either reloading the current data or getting new data.
In server push, a HTTP connection is held open for an indefiniteperiod of time (until the server knows it is done sending data to theclient and sends a terminator, or until the client interrupts theconnection). In client pull, HTTP connections are never held open;rather, the client is told when to open a new connection, and whatdata to fetch when it does so.
In server push, the magic is accomplished by using a variant of theMIME message format "multipart/mixed", which lets a single message (orHTTP response) contain many data items. In client pull, the magic isaccomplished by an HTTP response header (or equivalent HTML tag) thattells the client what to do after some specified time delay.
We‘ll explore client pull first...
CLIENTPULL
A simple use of client pull is to cause a document to be automaticallyreloaded on a regular basis. For example, name the following document"doc1.html" and try loading it in Netscape Navigator 1.1:
Document ONE

This is Document ONE!

Here‘s some text.


You will notice that the document reloads itself once a second.
What‘s happening? Simply put, we‘re using the META tag(a standard HTML 3.0 tag, for simulating HTTP response headers in HTMLdocuments) to tell the browser that it should pretend that the HTTPresponse when "doc1.html" was loaded included the following header:
Refresh: 1
That HTTP header, in turn, tells the browser to go reload (refresh)this document after 1 second has elapsed. If we wanted to wait 12seconds instead, we could have used this HTML directive:

...which is equivalent to this HTTP response header:
Refresh: 12
Note: You should make sure the META tag is used insidethe HEAD of your HTML document. That means it must appear before anytext or images that would be displayed as part of your document.So that‘s pretty cool.
A couple things to notice:
In this example, a new "Refresh" directive (via either the META tag or the Refresh HTTP response header) is given as a part of every retrieval. This is an important point. Each individual "Refresh" directive is one-shot and non-repeating. The directive doesn‘t say "go get this page every 6 seconds from now until infinity"; it says "go get this page in 6 seconds".
If you want continuous reloading, you have to give the directive on each retrieval. If you only want the document reloaded once, only give the directive on the first retrieval.
Once given the directive, the browser will do the specified retrieval after the specified amount of time. The only way to cause it not to happen is to not have an open window that contains the document.
This also means that if you set up an "infinite reload" situation (as the example above does), the only way you can interrupt the infinite reloading is by pressing the "Back" button or otherwise going to a different URL in the current window (or, equivalently, by closing the current window).
So another thing you obviously want to do, in addition to causing thecurrent document to reload, is to cause another document to bereloaded in n seconds in place of the current document. Thisis easy. The HTTP response header will look like this:
Refresh: 12; URL=http://foo.bar/blatz.html
The corresponding META tag would be:

Important note: make sure the URL you give is fully qualified(e.g. http://whatever/whatever). That is, don‘t use a relativeURL.
Here are two example documents, "doc2.html" and "doc3.html", each ofwhich causes the other to load (so if you load one of them, yourbrowser will flip back and forth between them indefinitely). Here‘s"doc2.html":
Document TWO

This is Document TWO!

Here‘s some other text.


Document THREE

This is Document THREE!

Here‘s yet more text.


(You should tweak the URLs to match your local system. Remember, theymust be fully specified.)
Now load one of the documents; the browser will load the other in 1second, then the first in another second, then the second again inanother second, and so on forever.
How do you make it stop? The easiest way is to either close thewindow, or put a link in the document(s) that points to somewhereelse. Remember, any retrieval of any document can cause the wholeprocess to stop at any point in time if a fresh directive isn‘t issued-- the process only continues as long as each new document causes itto continue. Thus, the content creator has total control.
Neat trick: the interval can be 0 seconds! This will cause thebrowser to load the new data as soon as it possibly can (after thecurrent data is fully displayed).Another neat trick: the data that is retrieved can be of anytype: an image, an audio clip, whatever. One fun thing to envision is0-second continuous updating of a live image (e.g. a camera feed), ora series of still images. Poor man‘s animation, kind of. We‘reconsidering mounting a camouflaged IndyCam on the prow of Jim Clark‘sboat and feeding live images to the world using this mechanism.Yet another neat trick: a "Refresh" header can be returned aspart of any HTTP response, including a redirection. So a single HTTPresponse can say "go get this URL now, and then go get this other URLin 10 seconds".
This means you can have a continuous random URL generator! Have anormal random URL generator (such asURouLette)that returns as part of its redirection response a "Refresh" directivethat causes the browser to go get another random URL from the randomURL generator in 18 seconds.
SERVERPUSH
Server push is the other dynamic document mechanism, complementingclient pull.
In contrast to client pull, server push takes advantage of aconnection that‘s held open over multiple responses, so the server cansend down more data any time it wants. The obvious major advantage isthat the server has total control over when and how often new data issent down. Also, this method can be more efficient, since new HTTPconnections don‘t have to be opened all the time. The downside isthat the open connection consumes a resource on the server side whileit‘s open (only when the server knows it wants this to happen,though). Also, server push has two other advantages: one is that aserver push is easily interruptible (you can just hit "Stop" andinterrupt the connection), and the other advantage we‘ll talk about alittle later.
First, a short review: the MIME message format is used by HTTP toencapsulate data returned from a server in response to a request.Typically, an HTTP response consists of only a single piece of data.However, MIME has a standard facility for representing many pieces ofdata in a single message (or HTTP response). This facility uses astandard MIME type called "multipart/mixed"; a multipart/mixed messagelooks something like:
Content-type: multipart/mixed;boundary=ThisRandomString--ThisRandomStringContent-type: text/plainData for the first object.--ThisRandomStringContent-type: text/plainData for the second and last object.--ThisRandomString--
The above message contains two data blocks, both of type "text/plain".The final two dashes after the last occurrence of "ThisRandomString"indicate that the message is over; there is no more data.
For server push we use a variant of "multipart/mixed" called"multipart/x-mixed-replace". The "x-" indicates this type isexperimental. The "replace" indicates that each new data block willcause the previous data block to be replaced -- that is, new data willbe displayed instead of (not in addition to) old data.
So here‘s an example of "multipart/x-mixed-replace" in action:
Content-type: multipart/x-mixed-replace;boundary=ThisRandomString--ThisRandomStringContent-type: text/plainData for the first object.--ThisRandomStringContent-type: text/plainData for the second and last object.--ThisRandomString--
The key to the use of this technique is that the server does not pushthe whole "multipart/x-mixed-replace" message down all at once butrather sends down each successive data block whenever it seesfit. The HTTP connection stays open all the time, and the serverpushes down new data blocks as rapidly or as infrequently as it wants,and in between data blocks the browser simply sits and waits for moredata in the current window. The user can even go off and do otherthings in other windows; when the server has more data to send, itjust pushes another data block down the pipe, and the appropriatewindow updates itself.
So here‘s exactly what happens:
Following in the tradition of the standard "multipart/mixed", "multipart/x-mixed-replace" messages are composed using a unique boundary line that separates each data object. Each data object has its own headers, allowing for an object-specific content type and other information to be specified.
The specific behavior of "multipart/x-mixed-replace" is that each new data object replaces the previous data object. The browser gets rid of the first data object and instead displays the second data object.
A "multipart/x-mixed-replace" message doesn‘t have to end! That is, the server can just keep the connection open forever and send down as many new data objects as it wants. The process will then terminate if the user is no longer displaying that data stream in a browser window or if the browser severs the connection (e.g. the user presses the "Stop" button). We expect this will be the typical way people will use server push.
The previous document will be cleared and the browser will begin displaying the next document when the "Content-type" header is found, or at the end of the headers otherwise, for a new data block.
The current data block (document) is considered finished when the next message boundary is found.
Together, the above two items mean that the server should push down the pipe: a set of headers (most likely including "Content-type"), the data itself, and a separator (message boundary). When the browser sees the separator, it knows to sit still and wait indefinitely for the next data block to arrive.
Putting it all together, here‘s a Unix shell script that will causethe browser to display a new listing of processes running on a serverevery 5 seconds:
#!/bin/shecho "HTTP/1.0 200"echo "Content-type: multipart/x-mixed-replace;boundary=---ThisRandomString---"echo ""echo "---ThisRandomString---"while truedoecho "Content-type: text/html"echo ""echo "

Processes on this machine updated every 5 seconds

"echo "time: "dateecho "

"echo "

"ps -elecho "---ThisRandomString---"sleep 5done<br>Note that the boundary is sent to the browser before the sleepstatement. This ensures that the browser will flush its buffers anddisplay all the data that‘s been received up to that point to theuser.<br>Special note to NCSA HTTPD users: You must not useany spaces in your content type, this includes the boundary argument.NCSA HTTPD will only accept a single string with no white spaceas a content type. If you put any spaces in the line (besidesthe one right after the colon) any text after the white spacewill be truncated.<br>As an example, the following will work:<br>Content-type: multipart/x-mixed-replace;boundary=ThisRandomStringThe following will not work:Content-type: multipart/x-mixed-replace; boundary=ThisRandomStringTHEAFOREMENTIONEDOTHERADVANTAGE TOSERVERPUSH<br>You can use server push for individual inlined images! Yes, that‘sright -- you can have a document that contains an image that getsupdated by the server on a regular basis or any time the serverwants. Just have the SRC attribute of theIMG tag point to an URL for which the server pushes aseries of images.<br>Let‘s stress this point: if you use server push for an individualinlined image, the image will get replaced inside the document eachtime a new image is pushed -- the document itself won‘t get touched(assuming it isn‘t separately subject to server push).<br>So this is kind of cool -- poor man‘s animation inlined into a staticdocument.<br>EFFICIENCYCONSIDERATION<br>Server push: generally more efficient, since a new connection doesn‘tneed to be opened for each new piece of data. Since a connection isheld open over time, even when no data is being transferred, theserver must be willing to accept dedicated allocation of a TCP/IPport, which may be an issue for servers with a sharply limited numberof TCP/IP ports.<br>Client pull: generally less efficient, since a new connection must beopened for each new piece of data. However, no connection is heldopen over time.<br>Note that in real world situations it is common for establishment of anew connection to take a significant amount of time -- i.e., onesecond or more. Given that this is the case, server push willprobably be generally preferable for end-user performance reasons,particularly for information that is frequently updated.<br>Another consideration is that the server has comparatively morecontrol in the server push situation than in the client pullsituation. One example: there is one distinct open connection foreach instance of server push in use, and the server can elect to (forexample) shut down such a connection at any time (e.g., via a crondaemon) without requiring a whole lot of logic in the server. On theother hand, the same application using client pull will look like manyindependent connections to the server, and the server may need to havea considerable level of complexity in order to manage the situation(e.g., associating client pull requests with particular end users tofigure out who to stop sending new "Refresh" headers to).<br>An Important Note On Server Push And Shell Scripts: If youwrite a CGI program as a shell script, and the script implements someform of server push where you expect the connection to be open for along time (e.g. an infinitely long stream of images representing livevideo), then the shell script normally will not notice when/if theuser severs the connection on the client side (e.g., by pressing the"Stop" button) and will continue running. This is bad, as serverresources will be thereafter consumed wastefully and uselessly. Theeasiest way to work around this shell script limitation is toimplement such CGI programs using a language like Perl or C -- suchprograms will terminate properly when the user breaks theconnection.<br>ANEXAMPLE<br>Mozilla icon animation -- an inlinedanimation in a static document, via server push.</div> <div class="list-group"> <a href="/article/204717" class="list-group-item">An Exploration of Dynamic Documents</a> <a href="/article/258686" class="list-group-item">Index of Linux Kernel Documents</a> <a href="/article/10337" class="list-group-item">The End of an Era</a> <a href="/article/1289566" class="list-group-item">"The End of an Era"</a> <a href="/article/217023" class="list-group-item">Caught in the act: The dynamic dance of enzymes...</a> <a href="/article/244583" class="list-group-item">美国历史文献选集 Living Documents of American History</a> <a href="/article/245603" class="list-group-item">美国历史文献选集 Living Documents of American HistoryAAA</a> <a href="/article/248388" class="list-group-item">...美国历史文献选集 Living Documents of American History</a> <a href="/article/551819" class="list-group-item">美国历史文献选集 Living Documents of American History</a> <a href="/article/1025398" class="list-group-item">...美国历史文献选集 Living Documents of American History</a> <a href="/article/1614714" class="list-group-item">(美国历史文献选集 Living Documents of American History)</a> <a href="/article/45904" class="list-group-item">Toward an Economics of Sustainable Urbanization</a> <a href="/article/67665" class="list-group-item">An Outline Of Reading Theory And Practice</a> <a href="/article/102939" class="list-group-item">Followership: An Essential Element of Leaders...</a> <a href="/article/127938" class="list-group-item">An architectural plan of the cell</a> <a href="/article/359533" class="list-group-item">An Overview of ESD Protection Devices</a> <a href="/article/538891" class="list-group-item">An Odd Sense of Timing: Scientific American</a> <a href="/article/762103" class="list-group-item">Toward an Economics of Sustainable Urbanization</a> <a href="/article/1038507" class="list-group-item">Chapter 2: An Overview of WebCore</a> <a href="/article/2182426" class="list-group-item">12.Set the HTML of an element</a> <a href="/article/617195" class="list-group-item">A Web Middleware Architecture for Dynamic Customization of Content for Wireless Clients</a> <a href="/article/96595" class="list-group-item">An XML- and State Machine-based Design of a W...</a> <a href="/article/119520" class="list-group-item">1.3. Part 1: Integration of an HTML template</a> <a href="/article/128885" class="list-group-item">1.2. Integration of an HTML page template - with TemplaVoila</a> </div> </div> </div> </div> </div> </div> <footer id="footer" class="footer hidden-print"> <div class="container"> <div class="panel panel-default"> <div class="panel-heading">相关问题</div> <div class="panel-body"> <a class="btn btn-default" href="/article/2608973" title="微软的虚拟Wifi网卡">微软的虚拟Wifi网卡</a> <a class="btn btn-default" href="/article/2608974" title="如何赚到人生的第一桶金?">如何赚到人生的第一桶金?</a> <a class="btn btn-default" href="/article/2608975" title="网友因"学生受审猝死案"发帖被公安领导起诉">网友因"学生受审猝死案"发帖被公安领导起诉</a> <a class="btn btn-default" href="/article/2608976" title="做男人 要满足女人的三种欲望">做男人 要满足女人的三种欲望</a> <a class="btn btn-default" href="/article/2608977" title="献给世上所有动过真情的人《放弃以后,才感到有些心痛》">献给世上所有动过真情的人《放弃以后,才感到有些心痛》</a> <a class="btn btn-default" href="/article/2608978" title="深圳亿万富翁回乡投资遭遇地产骗局后猝死">深圳亿万富翁回乡投资遭遇地产骗局后猝死</a> <a class="btn btn-default" href="/article/2608979" title="【摆脱新手小课堂--第二课】把图片拍得更清晰">【摆脱新手小课堂--第二课】把图片拍得更清晰</a> <a class="btn btn-default" href="/article/2608980" title="林彪主题阅读">林彪主题阅读</a> <a class="btn btn-default" href="/article/2608981" title="处事22计、伤心时要读的50句话和人的基本礼仪">处事22计、伤心时要读的50句话和人的基本礼仪</a> <a class="btn btn-default" href="/article/2608982" title="宋平担任中共甘肃省委第一书记兼省“革命委员会”主任、兰州军区第二政委。">宋平担任中共甘肃省委第一书记兼省“革命委员会”主任、兰州军区第二政委。</a> <a class="btn btn-default" href="/article/2608983" title="毛泽东颂歌精选十集(150首)">毛泽东颂歌精选十集(150首)</a> <a class="btn btn-default" href="/article/2608984" title="生活的感悟(转载)">生活的感悟(转载)</a> <a class="btn btn-default" href="/article/2608985" title="命理----《三命通會》卷七">命理----《三命通會》卷七</a> <a class="btn btn-default" href="/article/2608986" title="国家建设部的标准:《住宅装饰装修工程施工规范》GB50327-2001,凡马tx,好好学习...">国家建设部的标准:《住宅装饰装修工程施工规范》GB50327-2001,凡马tx,好好学习...</a> <a class="btn btn-default" href="/article/2608987" title="草它妈">草它妈</a> <a class="btn btn-default" href="/article/2608988" title="教你5招最实用解梦技巧">教你5招最实用解梦技巧</a> <a class="btn btn-default" href="/article/2608989" title="男人身体九大“报废”警告">男人身体九大“报废”警告</a> <a class="btn btn-default" href="/article/2608990" title="宋平:原中共中央政治局常委、组织部部长">宋平:原中共中央政治局常委、组织部部长</a> <a class="btn btn-default" href="/article/2608991" title="空间转帖周刊第二期_有趣八卦可爱搞笑一文打尽!">空间转帖周刊第二期_有趣八卦可爱搞笑一文打尽!</a> <a class="btn btn-default" href="/article/2608992" title="【摆脱新手小课堂--第四课】从EV值向曝光的本质说开去">【摆脱新手小课堂--第四课】从EV值向曝光的本质说开去</a> <a class="btn btn-default" href="/article/2608993" title="四纵五横法施法要诀--奇门遁甲 奇门 奇门 实用易经预测研究阅览室(五术藏书阁)">四纵五横法施法要诀--奇门遁甲 奇门 奇门 实用易经预测研究阅览室(五术藏书阁)</a> <a class="btn btn-default" href="/article/2608994" title="宽屏风景(可做博客顶图)欣赏(54P)">宽屏风景(可做博客顶图)欣赏(54P)</a> <a class="btn btn-default" href="/article/2608995" title="学会生存的75条人生忠告2">学会生存的75条人生忠告2</a> <a class="btn btn-default" href="/article/2608996" title="萝卜素丸子的做法">萝卜素丸子的做法</a> <a class="btn btn-default" href="/article/2608997" title="什锦鲜蔬[35P]">什锦鲜蔬[35P]</a> <a class="btn btn-default" href="/article/2608998" title="山之景”精美贴图集">山之景”精美贴图集</a> <a class="btn btn-default" href="/article/2608999" title="男人更长寿的八大另类建议">男人更长寿的八大另类建议</a> <a class="btn btn-default" href="/article/2609000" title="10岁前,决定孩子的一生">10岁前,决定孩子的一生</a> <a class="btn btn-default" href="/article/2609001" title="好色女人的十种表现">好色女人的十种表现</a> <a class="btn btn-default" href="/article/2609002" title="中共甘肃省委历届领导名录">中共甘肃省委历届领导名录</a> <a class="btn btn-default" href="/article/2609003" title="世界第一枚邮票"黑便士"将拍卖(图)">世界第一枚邮票"黑便士"将拍卖(图)</a> </div> </div></div> <div class="copy-right"> <p>神马文学网,客观、专业、权威的知识性互动百科全书。</p></div> </footer> </body> </html>