3

I am creating a website where users will be able to chat and send files to one another through a browser. I am using GWT for the UI and hibernate with gilead to connect to a mysql database backend.

What would be the best strategy to use so Users can interact together?

molleman
  • 2,934
  • 16
  • 61
  • 92

3 Answers3

2

I'd say you are looking for comet/AJAX|Server push/etc. See my previous answer on this matter for some pointers. Basically you are simulating inverting the communication between server and client - it's the server that's initiating the connection here, since it wants to, for example, inform the user that his/her friend just went online, etc.

The implementations of this technique change quite rapidly, so I won't make any definitive recommendations - choose the one that best suits your needs :)

Community
  • 1
  • 1
Igor Klimer
  • 15,321
  • 3
  • 47
  • 57
2

COMET is the technology that allows chatting over a web page - It is basically communicating through keep-alive connections. This allows servers to push information to the client. There are several implementations of this on the client side with GWT. Most servers nowadays support this, It is also part of the Servlet 3.0 spec (Which nobody has implemented yet)

Romain Hippeau
  • 24,113
  • 5
  • 60
  • 79
1

While COMET is very nice, it's not the only solution! Usual polling with time intervals (as opposed to COMET long polling) is still commonly used. It's also possible to require a manual refresh by the user.

Take Stackoverflow as an example - for most things you must refresh your browser manually to see the changes. I think, it's commonly perceived as normal and expected. COMET or frequent polling are an added bonus.

The problem with COMET is, that it can easily lead to lots of threads on the server. Except, if you additionally use asynchronous processing (also called "Advanced IO"), which is not too well supported yet (e.g. doesn't work with HTTPS in Glassfish v3 due to a severe bug), can lead to problems with Apache connectors etc.

The problem with frequent polling is, that it creates additional traffic. So, it's often necessary to make the polling less frequent, which will make it less convenient for the end user.

So you will have to weigh the options for your particular situation.

Chris Lercher
  • 37,264
  • 20
  • 99
  • 131
  • While normal web servers (Apache being the biggest offender, nginx the smallest ;)) don't cope well with this number of open connections, dedicated servers like APE (Ajax Push Engine) and better designed web servers like nginx are quite up to the challenge ;) IMHO, comet & co places a much lower strain on the server than constant polling every x seconds - and you need that x to be small, in order to keep client data up to date. Also, I don't think a full refresh is a solution here, since that would defeat the whole purpose of creating the website in GWT. – Igor Klimer Apr 16 '10 at 11:16
  • @Igor: I agree about the servers - it's just, that some people have no other choice than using Apache! With full refresh, I don't necessarily mean a full page refresh. It can also be a click on an update link/button that results in an Ajax call. And the question, what creates more strain on the server, Comet or constant polling, depends on several factors: If the messages arrive in an extremely fast pace, or if they're distributed quite evenly, then the COMET advantage is small - but since COMET is stateful, you always have the overhead of remembering its state. It really depends! – Chris Lercher Apr 16 '10 at 11:56