// // AHF 10/31/2002 // // Poker client // // // import java.awt.*; import java.rmi.*; import java.net.*; import java.util.*; import java.lang.*; public class PokerClient { ReturnMessage mes; // Most recent message from the server int id; // Unique ID for this client ClientInteraction ci; // Thread for interacting with the user GameServer gs; // Reference to the remote object CardSet hand; // Current hand boolean quit_request; // Set when the user has requested to quit boolean bet_now = false; // Set when the user is allowed to bet. int min_bet; // Minimum bet when the user does bet int max_bet; // Maximum bet when the user does bet public PokerClient(String username, String server) { boolean flag = true; quit_request = false; try { // Looks up the server using the name server on the host that // the applet came from. String serv = "rmi://" + server + "/PokerServer"; // Connect to the remote game server object gs = (GameServer)Naming.lookup(serv); // Start client interaction thread ci = new ClientInteraction(this); ci.start(); // Register this new player id = gs.Register(username); // Say hello System.out.println("Received ID " + id); System.out.println("We are playing stud poker... Please wait for game to begin."); System.out.println("Type \"?\" to get help."); // Loop to pick up new messages from the server while(flag) { // Get the next message from the server; this call will // block until a message is available from the server mes = gs.getMessage(id); // Service the message; synchronized so that we do not // make changes to the client's state that are // conflicting with those of the client interaction thread synchronized(this) { mes.service(this); }; }; // We need to catch all of these exceptions } catch (RemoteException e) { System.out.println("The poker server has disconnected."); System.exit(1); } catch (NotBoundException e) { System.out.println("PokerClient: object bind error (NotBoundException)"); System.exit(1); } catch (MalformedURLException e) { System.out.println("PokerClient: object URL specification error (MalformedURLException)"); System.exit(1); } } // Primary routine of the client public static void main(String args[]) { // Check number of arguments if (args.length!=1 && args.length!=2) { System.err.println("Usage: java PokerClient []"); return; } // Create the client object if(args.length == 1) { // If no host is specified, then assume the local host PokerClient obj = new PokerClient(args[0], "localhost"); }else{ PokerClient obj = new PokerClient(args[0], args[1]); }; }; };