【问题标题】:Pyro4 connect with javaPyro4 与 java 连接
【发布时间】:2015-02-12 22:03:25
【问题描述】:

大家好,我有关于 Pyro4 和 Java 的问题。我的问题是如何在 Java 中的 RMI 服务器和 Python 中的客户端 RMI 之间发送信息? 这是我的代码,我没有任何错误,但我无法发送任何内容。

Java 代码:

implements ReceiveMessageInterface
{
    int      thisPort;
    String   thisAddress;
    Registry registry;    // rmi registry for lookup the remote objects.

    // This method is called from the remote client by the RMI.
    // This is the implementation of the �gReceiveMessageInterface�h.
    public void receiveMessage(String x) throws RemoteException
    {
        System.out.println(x);
    }

    public RmiServer() throws RemoteException
    {
        try{
            // get the address of this host.
            thisAddress= (InetAddress.getLocalHost()).toString();
        }
        catch(Exception e){
            throw new RemoteException("can't get inet address.");
        }

        thisPort=3232;  // this port(registry�fs port)
        System.out.println("this address="+thisAddress+",port="+thisPort);
        try{
        // create the registry and bind the name and object.
        registry = LocateRegistry.createRegistry( thisPort );
            registry.rebind("rmiServer", this);
        }
        catch(RemoteException e){
        throw e;
        }
    }

    static public void main(String args[])
    {
        try{
        RmiServer s=new RmiServer();
    }
    catch (Exception e) {
           e.printStackTrace();
           System.exit(1);
    }
     }
}

这是我的 Python 代码:

导入 Pyro4

proxy=Pyro4.core.Proxy("PYRONAME:PhDJara/127.0.1.1")

print("5*11=%d" % proxy.multiply(5,11)) print("'x'*10=%s" % proxy.multiply('x',10))

感谢您的帮助。

jarain78

【问题讨论】:

  • Java 类的开头缺少一些东西。我看不出thIsAddress 字段的意义。 RMI 服务器不需要知道自己的 IP 地址。

标签: java python rmi


【解决方案1】:

是什么让您认为您应该能够将这两者联系起来? Pyro4 只是在概念上类似于 Java 的 RMI,但它们是两种完全不同的协议。您不能直接连接它们。

如果您想使用 Pyro 编写 Python 客户端并与服务器通信,则该服务器必须是 Pyro 服务器。在 Java 中创建一个的唯一方法是使用 Jython + Pyro。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-15
    • 2011-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多