public ChatRmiClient () {
		client = new Client();
		client.start();

		// Register the classes that will be sent over the network.
		Network.register(client);

		// Get the Player on the other end of the connection.
		// This allows the client to call methods on the server.
		player = ObjectSpace.getRemoteObject(client, Network.PLAYER, IPlayer.class);

		client.addListener(new Listener() {
			public void disconnected (Connection connection) {
				EventQueue.invokeLater(new Runnable() {
					public void run () {
						// Closing the frame calls the close listener which will stop the client's update thread.
						chatFrame.dispose();
					}
				});
			}
		});

		// Request the host from the user.
		String input = (String)JOptionPane.showInputDialog(null, "Host:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE,
			null, null, "localhost");
		if (input == null || input.trim().length() == 0) System.exit(1);
		final String host = input.trim();

		// Request the user's name.
		input = (String)JOptionPane.showInputDialog(null, "Name:", "Connect to chat server", JOptionPane.QUESTION_MESSAGE, null,
			null, "Test");
		if (input == null || input.trim().length() == 0) System.exit(1);
		final String name = input.trim();

		// The chat frame contains all the Swing stuff.
		chatFrame = new ChatFrame(host);
		// Register the chat frame so the server can call methods on it.
		new ObjectSpace(client).register(Network.CHAT_FRAME, chatFrame);
		// This listener is called when the send button is clicked.
		chatFrame.setSendListener(new Runnable() {
			public void run () {
				player.sendMessage(chatFrame.getSendText());
			}
		});
		// This listener is called when the chat window is closed.
		chatFrame.setCloseListener(new Runnable() {
			public void run () {
				client.stop();
			}
		});
		chatFrame.setVisible(true);

		// We'll do the connect on a new thread so the ChatFrame can show a progress bar.
		// Connecting to localhost is usually so fast you won't see the progress bar.
		new Thread("Connect") {
			public void run () {
				try {
					client.connect(5000, host, Network.port);
					// Server communication after connection can go here, or in Listener#connected().
					player.registerName(name);
				} catch (IOException ex) {
					ex.printStackTrace();
					System.exit(1);
				}
			}
		}.start();
	}