Figure 30-7 shows the various objects in the servlet-based chat application.
Each client is represented by two objects: a
URLChat object manages the GUI and translates user input into messages for the web server. The
URLChatWatcher thread periodically queries the server for new messages sent by the other users.
The communication is implemented by sending the server a GET request for the
ChatServlet object, with message details added as arguments to the URL. A client is identified by a name and a cookie. The cookie is presented to users when they send a
Figure 30-7. The servlet-based chat system
hi message to the servlet upon joining the chat system. Most messages require the name and cookie information, which verify the identity of the message sender.
The servlet maintains a synchronized
ChatGroup object, which bears many similarities to the
ChatGroup object used in the threaded chat application. Client information is held in
Chatter objects, while client messages are stored in a
A key difference between
ChatServlet and the server in the first chat example is that
ChatServlet cannot initiate communication with its clients. It must wait for a
URLChatWatcher thread to ask for messages before it can send them out.
URLChat transmits its messages as arguments attached to the URL http://localhost:8100/servlet/ChatServlet. The notation ...