Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Real-time server push?

Reply
Thread Tools

Real-time server push?

 
 
Martin
Guest
Posts: n/a
 
      05-18-2009
I have web-based user interface for an industrial automation system
that has some pages that display some activity and data in real time.
I have two distinctly different ways of doing this - both of which
have undesireable aspects.

1: I use AJAX - with the browser requesting a refresh once per second.
Since displayable information can be generated at any moment, I have
to buffer it on the server-side and then I have a time-stamp on each
piece of data so the client can tell if it's already displayed a
particular item. This all works ok but the display in the browser
isn't truely "real-time" - several events will appear on the screen at
the same instant even though they actually occurred at slightly
different times.

2: I have page set up that downloads a dll from the server that
contains a client-side socket that, when the page is loaded, connects
to a socket on the server. I then shove data in true real-time from
the server to the client page where it is displayed. All of the
client/page side activity is controlled by VBScript (and DHTML). The
problem here is that this works only with VBScript- and thus works
only in Internet Explorer.

I like the second approach better so, finally my question:

Does anyone know if there is program available anywhere (perhaps a
Java applet) that provides the same functionality as the DLL I'm
currently using but would have the ability to be manipulated by
Javascript? This would allow true real-time display of the data and
would work in all browsers. FWIW, Javascript is already being used on
all of my interface's pages.

Thanks for any recommendations.


 
Reply With Quote
 
 
 
 
Bart Van der Donck
Guest
Posts: n/a
 
      05-18-2009
Martin wrote:
> I have web-based user interface for an industrial automation system
> that has some pages that display some activity and data in real time.
> I have two distinctly different ways of doing this - both of which
> have undesireable aspects.
>
> 1: I use AJAX - with the browser requesting a refresh once per second.
> Since displayable information can be generated at any moment, I have
> to buffer it on the server-side and then I have a time-stamp on each
> piece of data so the client can tell if it's already displayed a
> particular item. This all works ok but the display in the browser
> isn't truely "real-time" - several events will appear on the screen at
> the same instant even though they actually occurred at slightly
> different times.
>
> 2: I have page set up that downloads a dll from the server that
> contains a client-side socket that, when the page is loaded, connects
> to a socket on the server. I then shove data in true real-time from
> the server to the client page where it is displayed. All of the
> client/page side activity is controlled by VBScript (and DHTML). The
> problem here is that this works only with VBScript- and thus works
> only in Internet Explorer.
>
> I like the second approach better so, finally my question:
>
> Does anyone know if there is program available anywhere (perhaps a
> Java applet) that provides the same functionality as the DLL I'm
> currently using but would have the ability to be manipulated by
> Javascript? This would allow true real-time display of the data and
> would work in all browsers. FWIW, Javascript is already being used on
> all of my interface's pages.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Realtime update</title>
<script type="text/javascript">
var refresh_int = 1000; // milliseconds
function realt() {
frames['r'].location = 'realtime.php?'+(new Date()).getTime();
setTimeout('realt()', refresh_int);
}
</script>
</head>
<body onLoad="realt()">
<iframe name="r"></iframe>
</body>
</html>

If MSIE's loading bar would be annoying, you could execute 'realt()'
in AJAX:

var x = null;
if (window.XMLHttpRequest) {
x = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
x = new ActiveXObject('Microsoft.XMLHTTP');
}
if (x != null) {
x.open('GET', 'realtime.php?'+(new Date()).getTime(), false);
x.send(null);
if (x.readyState == 4 && x.status == 200)
frames['r'].location = 'realtime.php?'+ (new Date()).getTime();
}
setTimeout('realt()', refresh_int);

Hope this helps,

--
Bart
 
Reply With Quote
 
 
 
 
Jorge
Guest
Posts: n/a
 
      05-18-2009
On May 18, 4:06*pm, Martin <(E-Mail Removed)> wrote:
> (...)
>
> Thanks for any recommendations.


http://groups.google.com/group/comp....d7a205968f2304

--
Jorge.
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      05-18-2009
On May 18, 10:57*am, Bart Van der Donck <(E-Mail Removed)> wrote:
> Martin wrote:
> > I have web-based user interface for an industrial automation system
> > that has some pages that display some activity and data in real time.
> > I have two distinctly different ways of doing this - both of which
> > have undesireable aspects.

>
> > 1: I use AJAX - with the browser requesting a refresh once per second.
> > Since displayable information can be generated at any moment, I have
> > to buffer it on the server-side and then I have a time-stamp on each
> > piece of data so the client can tell if it's already displayed a
> > particular item. This all works ok but the display in the browser
> > isn't truely "real-time" - several events will appear on the screen at
> > the same instant even though they actually occurred at slightly
> > different times.

>
> > 2: I have page set up that downloads a dll from the server that
> > contains a client-side socket that, when the page is loaded, connects
> > to a socket on the server. I then shove data in true real-time from
> > the server to the client page where it is displayed. All of the
> > client/page side activity is controlled by VBScript (and DHTML). The
> > problem here is that this works only with VBScript- and thus works
> > only in Internet Explorer.

>
> > I like the second approach better so, finally my question:

>
> > Does anyone know if there is program available anywhere (perhaps a
> > Java applet) that provides the same functionality as the DLL I'm
> > currently using but would have the ability to be manipulated by
> > Javascript? This would allow true real-time display of the data and
> > would work in all browsers. FWIW, Javascript is already being used on
> > all of my interface's pages.

>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> *"http://www.w3.org/TR/html4/loose.dtd">
> <html>
> *<head>
> * <title>Realtime update</title>
> * <script type="text/javascript">
> * *var refresh_int = 1000; // milliseconds
> * *function realt() *{
> * * frames['r'].location = 'realtime.php?'+(new Date()).getTime();
> * * setTimeout('realt()', refresh_int);
> * *}
> * </script>
> *</head>
> *<body onLoad="realt()">
> * *<iframe name="r"></iframe>
> *</body>
> </html>
>
> If MSIE's loading bar would be annoying, you could execute 'realt()'
> in AJAX:
>
> *var x = null;
> *if (window.XMLHttpRequest) *{
> * x = new XMLHttpRequest();
> *}
> *else if (window.ActiveXObject) *{
> * x = new ActiveXObject('Microsoft.XMLHTTP');
> *}
> *if (x != null) *{
> * x.open('GET', 'realtime.php?'+(new Date()).getTime(), false);
> * x.send(null);
> * if (x.readyState == 4 && x.status == 200)
> * *frames['r'].location = 'realtime.php?'+ (new Date()).getTime();
> *}
> *setTimeout('realt()', refresh_int);


Polling with IFrames or XHR is hardly real time. It's Comet or
nothing these days (at least for JS developers.)
 
Reply With Quote
 
Jorge
Guest
Posts: n/a
 
      05-18-2009
On May 18, 5:38 pm, David Mark <(E-Mail Removed)> wrote:
> (...)
> Polling with IFrames or XHR is hardly real time. It's Comet or
> nothing these days (at least for JS developers.)


1.- @the client: establish a comms channel with the server by sending
a request (an xmlHttpRequest), and return.

If/when the server has data to send:

2.- @the server: the server sends real time data through the
connection opened in step 1.
3.- @the client: data received: an onreadyestatechange event happens.
4.- @the client: the onreadyestatechange handler: gosub 1 and
processes the data received in step 3.

If the server has nothing to send:

2.- @the client: the connection established in step 1 will eventually
time out and trigger an onreadystatechange event with status !== 200.
3.- @the client: the onreadyestatechange handler: gosub 1 and return.

--
Jorge.
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      05-18-2009
On May 18, 1:32*pm, Jorge <(E-Mail Removed)> wrote:
> On May 18, 5:38 pm, David Mark <(E-Mail Removed)> wrote:
>
> > (...)
> > Polling with IFrames or XHR is hardly real time. *It's Comet or
> > nothing these days (at least for JS developers.)

>
> 1.- @the client: establish a comms channel with the server by sending
> a request (an xmlHttpRequest), and return.
>
> If/when the server has data to send:
>
> 2.- @the server: the server sends real time data through the
> connection opened in step 1.
> 3.- @the client: data received: an onreadyestatechange event happens.
> 4.- @the client: the onreadyestatechange handler: gosub 1 and
> processes the data received in step 3.
>
> If the server has nothing to send:
>
> 2.- @the client: the connection established in step 1 will eventually
> time out and trigger an onreadystatechange event with status !== 200.
> 3.- @the client: the onreadyestatechange handler: gosub 1 and return.


That's the pseudo-code for one transport. It's not the ideal choice
for most cases.
 
Reply With Quote
 
Jorge
Guest
Posts: n/a
 
      05-18-2009
On May 18, 8:48*pm, David Mark <(E-Mail Removed)> wrote:
> (...)
> It's not the ideal choice
> for most cases.


It might not be "ideal", but it works in ~ any browser and doesn't
require VB, Java, Flash nor SilverLight.

--
Jorge.
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      05-18-2009
On May 18, 4:15*pm, Jorge <(E-Mail Removed)> wrote:
> On May 18, 8:48*pm, David Mark <(E-Mail Removed)> wrote:
>
> > (...)
> > It's not the ideal choice
> > for most cases.

>
> It might not be "ideal", but it works in ~ any browser and doesn't
> require VB, Java, Flash nor SilverLight.


Nothing I have recommended requires any of those either. Your pseudo-
code demonstrates the LCD of the remaining choices. And it will not
work in any browser.
 
Reply With Quote
 
Richard Maher
Guest
Posts: n/a
 
      05-19-2009
Hi Martin,

"Martin" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> I have web-based user interface for an industrial automation system
> that has some pages that display some activity and data in real time.
> I have two distinctly different ways of doing this - both of which
> have undesireable aspects.
>
> 1: I use AJAX - with the browser requesting a refresh once per second.
> Since displayable information can be generated at any moment, I have
> to buffer it on the server-side and then I have a time-stamp on each
> piece of data so the client can tell if it's already displayed a
> particular item. This all works ok but the display in the browser
> isn't truely "real-time" - several events will appear on the screen at
> the same instant even though they actually occurred at slightly
> different times.
>
> 2: I have page set up that downloads a dll from the server that
> contains a client-side socket that, when the page is loaded, connects
> to a socket on the server. I then shove data in true real-time from
> the server to the client page where it is displayed. All of the
> client/page side activity is controlled by VBScript (and DHTML). The
> problem here is that this works only with VBScript- and thus works
> only in Internet Explorer.
>
> I like the second approach better so, finally my question:
>
> Does anyone know if there is program available anywhere (perhaps a
> Java applet) that provides the same functionality as the DLL I'm
> currently using but would have the ability to be manipulated by
> Javascript? This would allow true real-time display of the data and
> would work in all browsers. FWIW, Javascript is already being used on
> all of my interface's pages.
>
> Thanks for any recommendations.
>
>


If you just want a connection-oriented TCP/IP Java Socket example with one
server thread or process per client, then there are many Java examples on
the web. One such example is: -
http://manson.vistech.net/t3$examples/demo_client_web.html

All Java source code is in:
http://manson.vistech.net/t3$examples/
Warning: That code's a bit old now and optimistic in that it doesn't loop
around until a "complete" message has been read.

But again, personally, I suggest you use Java to create a UDP Socket as
in: -
http://groups.google.com/group/comp....999ef98ab29b24

You then subscribe to a service using Ajax or TCP/IP and tell them your Port
Number and IP Address. (UDP involves sequence checking, heartbeats, and
duplication detection) When you get an asynchronous message that requires
further action then you once again use the TCP/IP stream (or Ajax) to
perform the normal PULL transaction.Wrap it all up in IPsec and you're good
to go!

Cheers Richard Maher

PS. As mentioned in that thread/discussion, if you are using multicasting
then you can drop the "subscribe" step altogether and just subscribe to the
multicast group in the client. (Sandbox rules and certificates
notwithstanding.)


 
Reply With Quote
 
Martin
Guest
Posts: n/a
 
      05-19-2009
On Tue, 19 May 2009 08:12:50 +0800, "Richard Maher"
<(E-Mail Removed)> wrote:


>If you just want a connection-oriented TCP/IP Java Socket example with one
>server thread or process per client, then there are many Java examples on
>the web. One such example is: -
>http://manson.vistech.net/t3$examples/demo_client_web.html


Yes, a connection-oriented TCP/IP socket is what I'm looking for. The
link you provided is prompting for a userid and password so I can't
get to whatever is there.

I tried going to: manson.vistech.net but... Yikes, what is that?!

>All Java source code is in:
>http://manson.vistech.net/t3$examples/
>Warning: That code's a bit old now and optimistic in that it doesn't loop
>around until a "complete" message has been read.
>
>But again, personally, I suggest you use Java to create a UDP Socket as
>in: -
>http://groups.google.com/group/comp....999ef98ab29b24


>You then subscribe to a service using Ajax or TCP/IP and tell them your Port
>Number and IP Address. (UDP involves sequence checking, heartbeats, and
>duplication detection) When you get an asynchronous message that requires
>further action then you once again use the TCP/IP stream (or Ajax) to
>perform the normal PULL transaction.Wrap it all up in IPsec and you're good
>to go!
>
>Cheers Richard Maher
>
>PS. As mentioned in that thread/discussion, if you are using multicasting
>then you can drop the "subscribe" step altogether and just subscribe to the
>multicast group in the client. (Sandbox rules and certificates
>notwithstanding.)
>


I don't think there's any need for me to get into UDP or multi-casting
and the like.

I did not mention in my original post, but my situation is rather
simple. This user interface system operates only on an inTRAnet (not
on the internet). There will seldom be multiple users accessing pages
simultaneously - and even when that occurs, it would be very unlikely
to have more than 2 or 3 users at a time.

What I think I want is just to have a client-side socket that I can
send out in the page and, in the pageLoad event have it connect back
to a server-side socket. Then have it raise a "dataArrival" event when
data comes in and make the data available such that I can display it
using Javascript.

Another reason I want to stay with the socket concept is that I can
have the client connect directly to my interface process and get it's
data that way. IOW, my server-side scripts don't even need to get
involved with this.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help. Getting a An error has occurred while establishing a connectionto the server. When connecting to SQL Server 2005, this failure may be causedby the fact that under the default settings SQL Server does not allow remote aboutjav.com@gmail.com ASP .Net 0 05-03-2008 12:43 PM
Server to server = Server client to server? - Java 2 07-29-2005 10:46 PM
Copy file from server to server using server control button FileCopy() HELP =?Utf-8?B?UGVyZG8=?= ASP .Net 0 02-06-2004 08:11 PM
Windows Server 2003 Terminal Server - Different themes =?Utf-8?B?SGFha29u?= Microsoft Certification 0 01-15-2004 09:21 AM
minimum permissions required for access to a SQL Server session state server Mark Kamoski ASP .Net 7 08-09-2003 09:29 PM



Advertisments