Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP chatroom  RSS feed

 
Daniel Prene
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has anyone designed a chatroom in jsp that doesn't require refresh yet? Maybe combining it with ajax or some other technology...? I haven't been able to find much on google.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you say "in jsp"?? JSP is a presentation framework. No programmer should ever contemplate doing any complex computations "in jsp." Use helper classes - beans - custom tags, whatever - but don't put the logic "in jsp".
Bill
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. And heres why.
HTTP is a PULL protocol. The server can only send you information when you ask for it. Thats why JSP chat clients always need to refresh.

Proper chat clients make a permanent connection to the server, and the server broadcasts the message to all connected parties. You can't do that with a plain HTML page, even with Ajax.

Pushlets might be a solution, to that problem.

JSP is a technology unsuited to writing a "chat" application in. It is just the wrong tool for the job.

Cheers,
evnafets
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, you can do it with AJAX or without. The chat server just works differently. Instead of there being a permanent connection to each client, the messages being sent are written to a database and then the client request the most recent unread messages from the database which is then displayed.

I had a PHP chat app that worked this way. AJAX would just stop the page from having to be refreshed to pick up the latest messages.
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
agreed, that it is possible to write a chat application in JSP.
But I still think its the wrong tool.

It requires SOMETHING on the client to continually poll the server and look for new messages. Whether it is ajax doing this, or a page refresh - you are constantly issuing requests for the latest info. In a "realtime" chat application, you will want this refresh request sent fairly regularly.

This puts a much larger load on the server and network traffic compared to the more traditional chat application which can just sit there listening for messages and broadcast them directly to interested parties.

That is why I think JSP is unsuited to chat applications. Sure it will work, but to my mind, it is inefficient, and wouldn't scale as well as the more "traditional" style applet/application.

Cheers,
evnafets
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!