What would be the best way to create a JS chat client with GWT? The bit that I'm having trouble with is the persistence and transfer of the messages. Should I store the messages in a DB and check the db for new messages? Is there a much better way to do this?
Asked
Active
Viewed 3,472 times
2 Answers
3
Like jah suggested, you definitely want to use Comet/Server Push/Reverse AJAX/many other names. I've compiled your options for GWT in another post.
If you want a quick start, look at the NGiNX_HTTP_Push_Module - they have an easy to understand chat example. You'll have to write some handling of the protocol yourself, but it's a rather simple task.
If you're using Java too on the backend, the easier solution will be rocket-gwt or cometd.

Community
- 1
- 1

Igor Klimer
- 15,321
- 3
- 47
- 57
-
Thanks! I'll look into this - Server Push/whatever looks perfect for what I'm trying to accomplish. One more thing though, if you're still here: How should I store the messages on the server between them being sent and received? – Matthew H Mar 16 '10 at 21:39
-
1Like jah suggested - use a simple class, probably only with getters and setters, for that. You might also want to look into JavaScript Overlay Objects for much easier handling of JSON responses from the server: http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsOverlay.html – Igor Klimer Mar 16 '10 at 22:54
-
Btw, do you know if this will work on Google App Engine? Thank you! – Matthew H Mar 20 '10 at 23:23
-
1If you are using Google App Engine then my guess is rocket-gwt is the way to go - APE and nginx push module both require specialized servers, which AFAIK are not available on GAE. On the other hand, rocket-gwt should integrate pretty nicely - but I don't have much experience with GAE myself, so it's just a guess :) – Igor Klimer Mar 20 '10 at 23:32
2
You could either have connected clients continuously poll the server for new messages or you could have a look at Server Push: http://code.google.com/p/google-web-toolkit-incubator/wiki/ServerPushFAQ

jah
- 2,056
- 1
- 18
- 35
-
1No, there wouldn't be any need - unless you want to keep some kind of chat history on the server. – jah Mar 16 '10 at 21:30
-
Sorry, I am confused (new to GWT, too). Should I just use a standard data structure then to store the messages? – Matthew H Mar 16 '10 at 21:31
-
2Yes. Have a look at the NewMessageEvent class from a GWT chat application: http://code.google.com/p/gwt-eclipsecon-chat/source/browse/trunk/src/org/eclipsecon/gwt/chattr/client/ – jah Mar 16 '10 at 22:02