19.09.2015 Views

Prentice.Hall.Introduction.to.Java.Programming,.Brief.Version.9th.(2014).[sharethefiles.com]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

notifying a player is <strong>to</strong> invoke a method in the client that sets<br />

appropriate properties in the client or sends messages <strong>to</strong> a<br />

player. Figure 46.7 illustrates the relationship between clients<br />

and server.<br />

Figure 46.7<br />

The server coordinates the activities with the clients.<br />

All the calls a client makes can be encapsulated in one remote<br />

interface named TicTacToe (Listing 46.7), and all the calls the<br />

server invokes can be defined in another interface named CallBack<br />

(Listing 46.8). These two interfaces are defined as follows:<br />

Listing 46.7 TicTacToeInterface.java<br />

<br />

<br />

<br />

import java.rmi.*;<br />

public interface TicTacToeInterface extends Remote {<br />

/**<br />

* Connect <strong>to</strong> the TicTacToe server and return the <strong>to</strong>ken.<br />

* If the returned <strong>to</strong>ken is ' ', the client is not connected <strong>to</strong><br />

* the server<br />

*/<br />

public char connect(CallBack client) throws RemoteException;<br />

}<br />

/** A client invokes this method <strong>to</strong> notify the server of its move*/<br />

public void myMove(int row, int column, char <strong>to</strong>ken)<br />

throws RemoteException;<br />

Listing 46.8 CallBack.java<br />

<br />

<br />

<br />

<br />

import java.rmi.*;<br />

16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!