• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updating web page with events

 
Cuneyt Taskiran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I need to display text received from a serial device dynamically on a page. I wrote Java code that creates an event whenever one line of text is received. I am having difficulty in understanding how to implement a web-based listener that displays the lines on a page as they are received.
Desired functionality is something like this:
1) Client browser is pointed to the server URL
2) User gets N lines of text and displays them
3) A text available event is received at the server
... My code goes here
4) The new line is shown on client's browser, i.e. it now shows N+1 lines
5) Another text available event is received... etc

I am new to servlets and web programming so any help will be much appreciated.
Thanks,
Cuney
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The request/response cycle of HTTP is ill-suited to your needs.

Perhaps an Applet solution would make the most sense.

Otherwise, you'll need to have your pages poll the server periodically; perhaps employing Ajax.
[ November 18, 2008: Message edited by: Bear Bibeault ]
 
Cuneyt Taskiran
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A colleague mentioned Java Message System. Would JMS be able to handle this functionality? Would it be an overkill?
Thanks,
C
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JMS can do nothing to help the client update -- unless it's usable from an Applet (I have no idea).
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear ,

Why can't we go for Observer pattern in this situation ??
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't we go for Observer pattern in this situation ?

It is a form of Observer. But HTTP connections have a limited time of life, and can't be initiated by the server. The Observable (on the server) can't push notifications to the Observer (the browser) if there isn't a connection at that time. This can only happen the next time the browser polls the server.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dittmer , that explains me a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic