|
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 TutorialTutorial : Building an Internet Chat Application Questions and Answers
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.
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 )
public void actionPerformed (ActionEvent event )
The function is to register that the listener of the window messages generated by the frame is ChatClient.
The function is to register that the listener of the action message generated by the input is ChatClient.
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.
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.
Classes DataOutputStream and BufferedOutputStream.
Classes DataInputStream and BufferedInputStream.
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.
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.
|