• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple Java Chat online application  RSS feed

 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am developing a JSP,Servlet webapp, which should include a simple chat room application.
Does anyone know how I would make a start at this, or any online info that would be of help?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, is this homework? The gang here is happy to point students in good directions, but is reluctant to provide much code. You'll have more fun figgering it all out on your own. Just let us know where you're coming from.
Second, I think you'll have trouble without adding a little more to your "technology list". With JSP and Servlet there's no way to "push" a message from one user to another. So when I type "Hi!" we can't make the message show on your screen until you click something to ask for new messages. You'll probably want an applet to make the message show up instantly. Applets are moving slightly up the skills list and pushing messages from the server to an applet are a bit further yet. Which either makes them intimidating or just the kind of challenge you want. Let us know if you stopped breathing or jumped on the keyboard to ask for more.
On the other hand, if you're not married to JSP and Servlet, we might steer you to sockets. There's plenty good fun to be had there, too.
So let's get going! Izzit homework or no? What do you think of the technology choices?
 
Maarten Vergouwen
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun's SL275 course culminates in building a chat application; I'm sure you could find the source files somewhere of someone who has done the course (perhaps even Sun).
It's not exactly what you want (doesnt use servlets), but you could take it as a starting point perhaps.
[ March 03, 2004: Message edited by: Maarten Vergouwen ]
 
Annemarie McKeown
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help, nope not homework.
I have done something similar before using sockets, just wondering if there was a way of writing servlets to handle chat.
I'll go in the applet direction.
Thanks again.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using a vendor framework at work that has an applet they call "network presence" It allows the server to push events to the browser so they can be handled in JavaScript. I think the applet (acting as server) opens a ServerSocket and the server (now a client, just to be confusing) keeps a list of machine ort addresses that it believes to be logged on. The app has an "availability" switch on the UI that controls a little session object on the server so the server knows who is accepting messages. The vendor uses it to push all kinds of events to the browser. Pretty cool.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use servlets, and in fact it's been done I think.
What you need is a client that refreshes itself every second or so (maybe every few seconds if you don't mind having to wait a bit to see new lines appear).
Whenever you press enter after typing something the text is sent to the servlet and stored in a memory buffer.
When a client request the chat data that buffer is returned from the last point that client got the data the last time.
The client is responsible for caching the data it had retrieved in the past (to prevent heaps of network traffic and using loads of server resources).
The client request for data can be handled through sending HTTP requests from Javascript, which can then append the data to the content of any HTML control (this will require some pretty hefty Javascript coding, it's advanced stuff but not that long).
The servlet can keep track of which data has been sent to which client based on the session ID (say, keep a Map of session IDs mapped to the index in a List of entries).
When every client connected at the time it was posted has retrieved the first entry in the List it is deleted and all indices are updated to reflect this.
You might want to store the entry for logging purposes in a textfile or database, but if you do there may be legal challenges (privacy issues) to take into consideration.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!