Re: How to stream data in real time using Javascript?
- From: "d" <d@xxxxxxxxxxx>
- Date: Thu, 16 Feb 2006 17:41:33 GMT
"Charles" <me@xxxxxxxxxxx> wrote in message
news:op.s42txm0bix6gqv@xxxxxxxxxx
Hello, I have a specific need to stream text from a database to a browser
window in real time. Basically, I need this for a chat application such as
phplive. A browser window needs to display in real time new messages that
are stored on a remote database. I have studied how existing solutions
work, and this is not exactly the way I would like to do. Existing
solutions just use a javascript that refreshes every 5 seconds to see if
there is a new message, if so, it displays it in the window.
Is there a nicer way of doing it without the "refresh" hack?
Thanks,
There is a way... oh there is a way. It's heavily browser-dependent, as as
others have pointed out, HTTP isn't really made for this kind of thing.
Here's how it works: Modern browsers will render/interpret HTML chunks as
they're read from the server. If you have some PHP, say, that outputs
chunks of javascript (complete with its own script tags - very important),
as soon as the tag is closed, the browser will run the script. The PHP can
sleep or wait for new data, then start outputting script chunks when the
data is ready. If the connection is dropped, the php script will know
(using the connection-handling functions), and the window with the hidden
iframe containing the PHP URL will know (as the onload event will be fired).
If the iframe is refreshed only when the connection is dropped, you
essentially get streaming from server-side. It's not as efficient as
streaming binary data, but it works, and is reliable.
dave
--
Charles.
Desenvolvimento e criação de sites: www.auriance.com
Hospedagem de sites e servidores dedicados: www.auriance.net
.
- Follow-Ups:
- Re: How to stream data in real time using Javascript?
- From: Charles
- Re: How to stream data in real time using Javascript?
- From: Charles
- Re: How to stream data in real time using Javascript?
- References:
- How to stream data in real time using Javascript?
- From: Charles
- How to stream data in real time using Javascript?
- Prev by Date: Problem with 2 similar doms
- Next by Date: Re: handling onblur
- Previous by thread: Re: How to stream data in real time using Javascript?
- Next by thread: Re: How to stream data in real time using Javascript?
- Index(es):
Relevant Pages
|