File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Chat server with servlet..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Chat server with servlet....." Watch "Chat server with servlet....." New topic

Chat server with servlet.....

Kruger Brent

Joined: Jan 05, 2001
Posts: 26
Hello all,
In case the chat server is servlet based then,
1.the client applet opens a connection using url and urlconnection objects to servlet and passes login info.
2.the client applet then is ready to send messages and for each message that it sends, the urlconnection is again made to servlet.
3.the servlet on the other end stores this login info and messages, say in a hashtable.
4.the client applet then in its run() makes continuous request say every 3 seconds or so to the servlet (again opening a urlconnection) and servlet gets the stored message if any, and responses back.
a. Am I correct? Or is there a better way?
b. I have done as explained above and observed that for each message that a client sends, the doGet() of servlet is invoked and the response is made. It works. But how will the servlet handel the situation if there are say 100 clients sending messages?
c. Any comments or advice is seriously expected.

[This message has been edited by Kruger Brent (edited January 25, 2001).]
Kruger Brent

Joined: Jan 05, 2001
Posts: 26
No response???
rajani peddi
Ranch Hand

Joined: Nov 27, 2000
Posts: 73
hi Kruger Brent,
I guess that the server must be multithreaded to handle all the clients at the same time. You can start a new thread in the server each time a client makes a connection. I am not sure of this.... just my guess. i would appriciate if someone elaborates on this.
Thank you
Kruger Brent

Joined: Jan 05, 2001
Posts: 26
Thanks Rajani. But I dont think we require a thread to be spawned when it is with servlets because it has a built in process to spawn a thread for every client.
Even I hope some experts to disscuss here.
Kruger Brent

Joined: Jan 05, 2001
Posts: 26
[This message has been edited by Kruger Brent (edited January 30, 2001).]
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

myself, i would like to have your code. I cant seem to get an applet to talk to a servlet in Netscape only in IE.
my email is

Visit my download page
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
As I just posted in one of the other Chat threads, I have a servlet based chat in my Java Developer's GUide to Servlets and JSP - There is also one in Hunter's book.
With a servlet base you let the servlet container worry about the Threads.
There is no problem with handling 100 users - the key is to remove the responsibility of tracking the different chat rooms and messages from the servlet and put it in a separate object with appropriate synchronization.

author of:
I agree. Here's the link:
subject: Chat server with servlet.....
It's not a secret anymore!