Pyro4与j连接

2024-06-16 10:38:47 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,我有关于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编写的代码:

import 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))

谢谢你的帮助。在

雅兰78


Tags: the代码stringjavapublicthissystemregistry
1条回答
网友
1楼 · 发布于 2024-06-16 10:38:47

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

如果要使用Pyro编写Python客户机并与服务器对话,那么该服务器必须是Pyro服务器。在Java中创建一个的唯一方法是使用Jython+Pyro。在

相关问题 更多 >