Connecting Tech Pros Worldwide Forums | Help | Site Map

Push technology in javascript

giangiammy@gmail.com
Guest
 
Posts: n/a
#1: Jan 30 '06
hi all,

I need to implement a web page with a table:
the page structure i fixed, the tables field are updating from time to
time.

The table could be quite big, but just some fields change from time to
time.

I need an update delay of about 1s.

I think that the push technology could fit this requirements: do you
have some
links to examples or documentation of this type implementatiom
in HTML + JavaScript (or eventually using CGI?)

thanks for every information
giammy


The Magpie
Guest
 
Posts: n/a
#2: Jan 30 '06

re: Push technology in javascript


giangiammy@gmail.com wrote:[color=blue]
>
> I need to implement a web page with a table: [snip]
>
> I think that the push technology could fit this requirements: do you
> have some links to examples or documentation of this type implementatiom
> in HTML + JavaScript (or eventually using CGI?)
>[/color]
Javascript (though it can be used elsewhere) is essentially a
web-technology used in session-based interactive operations. What that
means is that it is basically a PULL system, rather than a PUSH one. To
implement a push-based system, you would need the web page to call a
server-side javascript that would then push the data to the web page and
keep itself alive throughought the whole session.

That would, naturally, slow the server down, keep the session busy more
than need be and consume a fair bit of bandwidth. You would also need to
keep checking that the session had not been shut down from the client
side, which is what remains essentially "in-charge" of the session.
Ronaldo Junior
Guest
 
Posts: n/a
#3: Jan 30 '06

re: Push technology in javascript


> Javascript (though it can be used elsewhere) is essentially a[color=blue]
> web-technology used in session-based interactive operations. What that
> means is that it is basically a PULL system, rather than a PUSH one. To
> implement a push-based system, you would need the web page to call a
> server-side javascript that would then push the data to the web page and
> keep itself alive throughought the whole session.[/color]

I was thinking about an Ajax request, constantly receiving data
(triggered by readystatechange) and updating the table. If the
connection is interrupted, the readyState would be 4 (completed), so
giving the possibility to catch a possible connection error.

I haven't tested 'cause I don't know how to make a PUSH page, but
anyway, wouldn't it work?

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#4: Jan 30 '06

re: Push technology in javascript


Ronaldo Junior wrote:
[color=blue][color=green]
>> Javascript (though it can be used elsewhere) is essentially a[/color][/color]

Please provide attribution of quoted material.
[color=blue][color=green]
>> web-technology used in session-based interactive operations. What that
>> means is that it is basically a PULL system, rather than a PUSH one. To
>> implement a push-based system, you would need the web page to call a
>> server-side javascript that would then push the data to the web page and
>> keep itself alive throughought the whole session.[/color]
>
> I was thinking about an Ajax request, constantly receiving data
> (triggered by readystatechange) and updating the table. If the
> connection is interrupted, the readyState would be 4 (completed),
> so giving the possibility to catch a possible connection error.[/color]

Definitely not.

Zeroth, it is not an "Ajax request". Ajax is a buzzword (often used
wrong), not a protocol. What you probably mean is a HTTP request via
an object implementing the IXMLHTTPRequest interface (here: x).

First, you have to understand that HTTP is not a stateful protocol (such as
e.g. FTP is). The server is allowed to end the connection immediately
after it sent the response to a client's request (using Keep-Alive can
prevent that if supported and sent by the client in intervals short
enough.)

Second, x.readyState == 4 merely indicates that the current request-response
cycle has ended. It does not mean that the connection has been severed.

Third, you can detect if a new connection could be established with that
approach or a previous one could be reused. However, in order to determine
if there was an error, you have to look for x.readyState < 4 or
x.status.test(/^(0|5\d\d)/).
[color=blue]
> I haven't tested 'cause I don't know how to make a PUSH page,[/color]

What do you mean by "PUSH page"?
[color=blue]
> but anyway, wouldn't it work?[/color]

Maybe.


PointedEars
Ronaldo Junior
Guest
 
Posts: n/a
#5: Jan 30 '06

re: Push technology in javascript


Thomas 'PointedEars' Lahn wrote:[color=blue]
> What do you mean by "PUSH page"?[/color]

Some page providing unlimited, streaming content, like a chat page. I
don't know how to make a page behave like this to test my suggestion.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#6: Jan 30 '06

re: Push technology in javascript


Ronaldo Junior wrote:
[color=blue]
> Thomas 'PointedEars' Lahn wrote:[color=green]
>> What do you mean by "PUSH page"?[/color]
>
> Some page providing unlimited, streaming content, like a chat page.[/color]

You cannot do this exactly with HTTP alone, it required a stateful protocol.
Even a "chat page" (by which you probably mean an HTML document including a
Java applet for the chat; Java != JavaScript) is not such a real-time
application.
[color=blue]
> I don't know how to make a page behave like this to test my suggestion.[/color]

However, you can make requests repeatedly, or even better, make requests
in defined not-too-short intervals. Try this for the second approach:

function update()
{
var me = arguments.callee;

// setRequestHeader(...)

me.x.onreadystatechange = function()
{
if (me.x.readyState == 4)
{
var st = me.x.status;

// request was successful
if (st == 200)
{
// update content in one second from now
me.intv = window.setTimeout("update()", 1000);
}

// request failed
else if (st.toString().test(/^[05])/))
{
// clear interval
window.clearInterval(me.intv);

// (update content to) display error message
}
}
}

me.x.send();
}
update.x = new XMLHttpRequest();
update.x.open("GET", "http://example.com/");

// update content in one second from now
update.intv = window.setTimeout("update()", 1000);

Note that since host objects are involved, you have to do feature tests on
runtime before:

<URL:http://www.jibbering.com/faq/faq_notes/not_browser_detect.html>


HTH

PointedEars
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#7: Jan 30 '06

re: Push technology in javascript


Thomas 'PointedEars' Lahn wrote:
[color=blue]
> [...]
> // request failed
> else if (st.toString().test(/^[05])/))[/color]

Should be

else if (/^[05]/.test(st.toString()))

(as it is RegExp.prototype.test().) Note that in JavaScript 1.6
(Mozilla/5.0 rv:1.7, incl. Firefox 1.5), the explicit type conversion
is not necessary:

else if (/^[05]/.test(st))


PointedEars
Jasen Betts
Guest
 
Posts: n/a
#8: Feb 3 '06

re: Push technology in javascript


On 2006-01-30, Ronaldo Junior <setembro@gmail.com> wrote:[color=blue][color=green]
>> Javascript (though it can be used elsewhere) is essentially a
>> web-technology used in session-based interactive operations. What that
>> means is that it is basically a PULL system, rather than a PUSH one. To
>> implement a push-based system, you would need the web page to call a
>> server-side javascript that would then push the data to the web page and
>> keep itself alive throughought the whole session.[/color]
>
> I was thinking about an Ajax request, constantly receiving data
> (triggered by readystatechange) and updating the table. If the
> connection is interrupted, the readyState would be 4 (completed), so
> giving the possibility to catch a possible connection error.
>
> I haven't tested 'cause I don't know how to make a PUSH page, but
> anyway, wouldn't it work?[/color]

it'd work. the server end can be tricky. there are apparently bugs in IE
that need to be avoided too.

--

Bye.
Jasen
Closed Thread