简体   繁体   中英

Possible to do client-side HTTP push?

Pretty much the opposite of server-side push, also known as Comet . I'm wondering if it is possible to use long lived HTTP connections to push information to the server.

Unlike a simple XHR, the connection would be kept alive and data would be streamed to the server at intervals, as the user completes actions etc.

Using standard technologies I don't believe this is possible, but I'm open to suggestions on possible exploitations or ingenious ways of accomplishing this. The purpose would be to complete low-latency data pushes to the server for fast and efficient one-directional streaming.

I'm not interested in using socket implementations with flash/java bridges because of the hassle of serving cross domain policies or getting the java signed. Crude hacks that work without additional dependencies are welcome. Preferably the solution would be done with javascript.

This can be done in one of a few ways ...

You can keep a connection open and do POST's, or I am sure it is possible to do a multi-part POST.

I once saw a talk by the guy behind http://orbited.org/

It's a js library that uses standard technology to keep a connection open between the server and the client you can push stuff down.

this does it: http://www.speich.net/projects/programming/firebug-testing.php

and look at this: http://en.wikipedia.org/wiki/Comet_(programming )) and google around for 'x-mixed-replace'

Do your XHR on Firefox. Must use it directly or grab XHR object to set funny fields. xhr.multipart=true and use the onload handler, not onreadystatechange.

The server should return data with mime type 'multipart/x-mixed-replace'. plus a multipart separator. flush to get the last bytes out for each salvo. I'm still trying to get it smooth.

Safari (~=chrome) can do it but the particulars are different. Call your handler when readyState=3, not 4. And every time the new text is Appended to resultText, not all alone. Can't get anything to work on IE.

If you're looking for bi-directional browser-server communication, you're probably looking for WebSockets . See at the bottom of the Wikipedia article for available implementations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM