BrokeredChat - /* This applet supports two-way chatting...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* This applet supports two-way chatting between users. It implements a client for the ConnectionBroker server, which can set up a relayed connection between a pair of such clients. There are really two functions: The user can register with the server as a client who is willing to accept a connection, or the user can make a connection with one of the clients who is waiting on the server. The applet retrieves and displays a list of waiting clients when it starts. There is a Refresh button that the user can click to refresh this list (since the list of waiting clients can change from time to time). The user connects with one of the clients on the list by clicking it and then clicking a Connect button. Finally, there is a register button that will add the user to the list and then wait for a connection. There is an input box where the user can enter a name or other information to be displayed in other users' client lists. The use can be a party to multiple connections simultaneously. A separater window opens for each connection that can be used to send and retrieve messages. (Note that there is nothing to stop a user from chatting with him or herself.) An applet parameter named "server" can be used to specify the name or IP number of the server computer. If none is specified, the computer from which the applet was loaded is used. Another applet parameter, named "port", can be used to specify the port on which the server is listening. If none is specified, then the port given by the constant DEFAULT_PORT is used. This class can also be run as a standalone application. In that case, the server must be specified as the first command-line parameter. The port, if differnent from the DEFAULT_PORT, can be specified as the second parameter. */ * import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import java.applet.Applet; import java.util.Vector; i public class BrokeredChat extends Applet implements Runnable, ActionListener, ItemListener { public static void main(String[] args) { // Run the applet as a standalone program in its own window, // using information about the server from the command line. if (args.length == 0) { System.out.println("Usage: java BrokeredChat <server> [<port>]"); return; } BrokeredChat applet = new BrokeredChat(); applet.computer = args[0]; // Set these values so the applet applet.port = DEFAULT_PORT; // won't do it when it starts. if (args.length > 1) { try { applet.port = Integer.parseInt(args[1]); } catch (NumberFormatException e) { }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
} applet.init(); Frame window = new Frame("BrokeredChat"); window.add(applet, BorderLayout.CENTER); window.setSize(450,350); window.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent evt) { System.exit(0); } } ); window.show(); applet.start(); } /* Command chars that are used for communicating with the
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2010 for the course CSC 115 taught by Professor Jackson during the Spring '09 term at University of Victoria.

Page1 / 7

BrokeredChat - /* This applet supports two-way chatting...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online