【发布时间】: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 地址。