A MUD Client

Example 21-8 is a client program for the MUD system developed in the previous examples. It uses the Naming.lookup( ) method to look up the RemoteMudServer object that represents a named MUD on a specified host. The program then calls the getEntrance( ) or getNamedPlace( ) method of this RemoteMudServer object to obtain an initial MudPlace object into which to insert the user. Next, the program asks the user for a name and description of the MudPerson that will represent him in the MUD, creates a MudPerson object with that name and description, and then places it in the initial RemoteMudPlace. Finally, the program enters a loop that prompts the user to enter a command and then processes the command. Most of the commands that this client supports simply invoke one of the remote methods of the RemoteMudPlace that represents the user’s current location in the MUD. The end of the command loop consists of a number of catch clauses that handle the large number of things that can go wrong.

In order to use the MudClient class, you must first have a MudServer up and running. You should be able to accomplish that with commands like the following:

% cd je3/rmi
% javac Mud*.java
% rmic -d ../../../../ je3.rmi.MudServer
% rmic -d ../../../../ je3.rmi.MudPlace
% rmic -d ../../../../ je3.rmi.MudPerson
% rmiregistry &
% java je3.rmi.MudServer MyMud muddy Lobby \
    'A large marble lobby with ficus trees'

Having started the server with these commands, you can then run the client ...

Get Java Examples in a Nutshell, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.