|
|
|
Advertisement
|
It's time to take the example out for a spin. Once you have all the Jini services up and running (see Resources if you need help), you start the game service with a command similar to this (on the Windows platform):
java -Djava.security.policy=C:\jini1_0_1\example\books\policy.all
-cp .;C:\jini1_0_1\lib\jini-core.jar;C:\jini1_0_1\lib\jini-ext.jar;
C:\jini1_0_1\lib\sun-util.jar;C:\jini1_0_1\lib\space-examples.jar;
javaworld.gameservice.GameService "Fun Game" 2
Here, the two command-line arguments specify that the service should create a game ("Fun Game") that permits a maximum of two players at any time. Then you can start up as many clients as you want, using commands similar to these:
java -Djava.security.policy=C:\jini1_0_1\example\books\policy.all
-cp .;C:\jini1_0_1\lib\jini-core.jar;C:\jini1_0_1\lib\jini-ext.jar;
C:\jini1_0_1\lib\sun-util.jar;
javaworld.gameservice.Player "Fun Game" duke
java -Djava.security.policy=C:\jini1_0_1\example\books\policy.all
-cp .;C:\jini1_0_1\lib\jini-core.jar;C:\jini1_0_1\lib\jini-ext.jar;
C:\jini1_0_1\lib\sun-util.jar;
javaworld.gameservice.Player "Fun Game" mickey
java -Djava.security.policy=C:\jini1_0_1\example\books\policy.all
-cp .;C:\jini1_0_1\lib\jini-core.jar;C:\jini1_0_1\lib\jini-ext.jar;
C:\jini1_0_1\lib\sun-util.jar;
javaworld.gameservice.Player "Fun Game" minnie
With these commands, you've started three players who want to play Fun Game -- "duke," "mickey," and "minnie." However, only two of them can play at any time. You'll see output in each player window similar to the following:
Got a matching service.
Trying to get ticket to Fun Game
Got a ticket to Fun Game
Playing game Fun Game
Left the game Fun Game
Trying to get ticket to Fun Game
Got a ticket to Fun Game
Playing game Fun Game
Left the game Fun Game
Trying to get ticket to Fun Game
...
In the window for the game service, you'll see output similar to this:
found JavaSpaces = com.sun.jini.outrigger.SpaceProxy@1
Discovered new lookup service
serviceID initialized to 123907da-3cde-483c-8f7b-bb46e9fbd8ae
...
minnie is playing...
duke is playing...
minnie is playing...
duke is playing...
minnie is playing...
duke is playing...
minnie is playing...
duke is playing...
mickey is playing...
duke is playing...
mickey is playing...
mickey is playing...
mickey is playing...
mickey is playing...
minnie is playing...
minnie is playing...
duke is playing...
...
If you pay close attention to the players' windows, you'll see that only two players are playing at any time, while the third waits for a ticket. When a player is finished, relinquishes the ticket, and goes to sleep for a bit, the waiting player gets a chance to grab the newly available ticket and start playing.
|
Sponsored Links
|