Recent Changes - Search:

Distributed Computing

This website demonstrates using wikis as teaching and learning tool.

The course instructor is also happy to share the teaching materials here with those who find it readable.

Suggested Answers to Tutorial

Tutorial : Building an Internet Chat Application


Questions and Answers

  • 1. Why does the class ChatClient need to implement the interfaces ActionListener and WindowListener?
The class implements the interface ActionListener so that we can handle the event when the user hits return in the input text area. The class implements the interface WindowListener so that we can handle window messages such as closing the window.
  • 2. State all the methods a class needs to provide when it implements the interface WindowListener?
	public void windowOpened ( WindowEvent event )
	public void windowClosing ( WindowEvent event )
	public void windowClosed ( WindowEvent event )
	public void windowIconified ( WindowEvent event )
	public void windowDeiconified( WindowEvent event )
	public void windowActivated ( WindowEvent event )
	public void windowDeactivated( WindowEvent event )
  • 3. State all the methods a class needs to provide when it implements the interface ActionListener?
	public void actionPerformed (ActionEvent event )
  • 4. What is function of the following statement in the constructor: frame.addWindowListener (this);
The function is to register that the listener of the window messages generated by the frame is ChatClient.
  • 5. What is function of the following statement in the constructor: input.addActionListener (this);
The function is to register that the listener of the action message generated by the input is ChatClient.
  • 6. What is the advantage of using the readUTF() and writeUTF() methods of data streams to send and receive text?
The readUTF() and writeUTF() methods provide encapsulated String transmissions so that we can easily identify each separate message from clients, which makes processing the communications simpler.
  • 7. How does a ChatHandler know the total number of the connected ChatClients and where are they when it broadcasts messages to them?
A list of the current connections is maintained with a static Vector within the class ChatHandler. The broadcast() method uses this list to transmit a message to all connected clients.
  • 8. Which two stream classes are used in constructing the output stream of ChatHandler?
Classes DataOutputStream and BufferedOutputStream.
  • 9. Which two stream classes are used in constructing the input stream of ChatHander?
Classes DataInputStream and BufferedInputStream.
  • 10. What is the major reason for applying DataOutputStream and DataInputStream when communicating between ChatHandler and ChatClient?
These stream classes allow us to encapsulate each message of a chat system within a UTF-formatted text string, which is much easier to handle than simple characters.
  • 11. Why do we need to synchronize the list of chat handlers in the method broadcast()?
This is to avoid people joining or leaving the chat server while we are broadcasting messages. It ensures that we send messages to every one who connected and do not send messages to someone who no longer exists.
Edit - History - Print - Recent Changes - Search
Page last modified on November 28, 2008, at 04:34 PM