【问题标题】:java rmi multiple clients same applicationjava rmi多个客户端相同的应用程序
【发布时间】:2013-11-11 15:39:33
【问题描述】:

我正在尝试在 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");
    }
    } 
}

我如何为每个客户制作一个单独的新游戏? 提前致谢!

【问题讨论】:

    标签: java client-server rmi


    【解决方案1】:

    注册表中的对象应该是工厂对象。客户端应该查找它,然后调用返回一个新游戏的工厂方法,它应该是另一个远程对象。

    【讨论】:

      猜你喜欢
      • 2011-11-25
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 2019-07-18
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2010-12-21
      相关资源
      最近更新 更多