我正在尝试在 java 中做一个 RMI mastermind 应用程序,其中每个客户端都需要一个来自服务器的单独游戏,但不知何故,每个运行的新客户端的组合都附加到一个游戏中,所以就好像每个新客户端都加入了主游戏。
这是我的服务器代码:
public class MastermindServer
{
public static void main(String[] args) throws RemoteException, MalformedURLException
{
try
{
java.rmi.registry.LocateRegistry.createRegistry(1111);
System.out.println("RMI registry ready...");
}
catch (Exception e)
{
e.printStackTrace();
System.out.println("Exception starting RMI registry");
}
Naming.rebind("//localhost:1111/MastermindServer", new MastermindImplementation());
}
}
和我的客户代码:
public class MastermindClient
{
private static MastermindMenuGUI menuFrame;
public static void main(String[] args)
{
System.out.println("before try catch");
try {
Registry clientRegistry = LocateRegistry.getRegistry("127.0.0.1",1111);
System.out.println("Client registry " + clientRegistry);
MastermindInterface game = (MastermindInterface) clientRegistry.lookup("theGame") ;
System.out.println("Client ready");
System.out.println(game.createCombination());
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Exception in client");
}
}
}
我如何为每个客户制作一个新的独立游戏?提前致谢!