This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chat Servlet

 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a chat application where i want the Servlet to be called whenever there is a message in the Inbox [from the DB].

Any suggestions is highly appreciated. Thanx in advance.

Regards
Roshini
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interesting concept. Good luck working on it, hope you come back to tell us about your progress?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roshini,
You are not in a right direction. Servlet is the technology not meant for this kinda stuff. Use socket programming instead. Or you can go with javaspaces too, but it would be complex for you.

and Jeroen,
Its not nice at all.
[ February 02, 2005: Message edited by: Adeel Ansari ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
quite nice I'd say. I encourage him? to go forward with the project and even express interest in what progress is made.
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the term "Application" has misleaded... I am literally sorry, i want to develop a Web Application for Chat

Hope i could get relevant idea.

Regards
Roshini
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets are "pull" technology. They sit and wait for requests from browsers (or any client that can make a request) and send a response. They don't have the ability to push data down to a browser.

The HTTP protocol is stateless, there is no constant connection from the client to the server so there is no way for a server to notify a client without a request.

Do some Googling on "Applet Chat Apps".
There are plenty open source and freeware projects out there.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
with some hefty Javascript it can be done though. Basically you need to have the browser poll the servlet for data every few seconds.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually had an invisible applet working once.
All the applet did was maintain a socket connect to a little server running on the same machine as the webserver. The applet did nothing more than force browser refresh.

Turned out to be more trouble than it was worth
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

with some hefty Javascript it can be done though. Basically you need to have the browser poll the servlet for data every few seconds.

Or you could do it with an HTML META tag. Both are fallible though, since not all browsers support the <META HTTP-EQUIV=Refresh /> tag, and JavaScript can't be guaranteed to work either. Ben's suggestion is your best bet.
[ February 02, 2005: Message edited by: Paul Sturrock ]
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks all for the ideas..

I infact thought of an alternate for the meta refresh, as Mr.Ben has suggested i was looking for some way to push information down to the client.

Anyway i will try go forward with meta tag refresh.

Have a Good time.

Regards
Roshini
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
meta refresh is simpler to implement but has the big disadvantage that the entire page is reloaded constantly.
By using JS you can just reload the content of the chatlog without reloading the entire page (possibly deleting whatever the user was typing in the progress).

As already stated, using a pure Java client instead of a browser interface is a cleaner solution.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...unless you are using frames. (Please don't take that as a recommendation: frames are ugly)

But of course this is a moot point - as others have already suggested, this is not a good way to go. Yet another disadvantage is that in Windows a sound is often tied to the refresh option - so constantly refreshing a page through IE can make your PC tick like a clock.
[ February 03, 2005: Message edited by: Paul Sturrock ]
 
Roshini Sridharan
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its true that the refresh is annoying to the user, i will include the JS to make things better.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic