首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pyro4与java连接

Pyro4与java连接
EN

Stack Overflow用户
提问于 2015-02-12 22:03:25
回答 1查看 501关注 0票数 1

嗨,我有关于Pyro4和Java的所有问题。我的问题是如何在Java中的RMI服务器和Python中的客户端RMI之间发送信息?这是我的代码,我没有任何错误,但我不能发送任何东西。

Java代码:

代码语言:javascript
复制
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") 打印(“5*11=%d”% proxy.multiply(5,11))打印(“x‘*10=%s”% proxy.multiply('x',10))

谢谢你的帮助。

jarain78

EN

回答 1

Stack Overflow用户

发布于 2015-02-14 17:56:14

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28488697

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档