Java RMI:连接被拒绝
我为RMI的客户端编写了以下代码。但获取
java.rmi.ConnectException: Connection refused to host: localhost; nested
exception is:
java.net.ConnectException: Connection refused: connect
代码:
import java.rmi.*;
import java.net.*;
import java.rmi.registry.*;
class client
{
public static void main(String [] ars)
{
Iface serv;
Registry r;
String serveraddr = ars[0];
String serverport = ars[1];
String text = "Hey jude";
System.out.println("Sending" + text);
try{
r = LocateRegistry.getRegistry(
serveraddr,
(new Integer(serverport)).intValue()
);
serv = (Iface) r.lookup("rmi://server");
serv.receive(text);
}
catch(Exception e){
System.out.println(e);
}
}
}
I have written following code for the client of RMI. But getting
java.rmi.ConnectException: Connection refused to host: localhost; nested
exception is:
java.net.ConnectException: Connection refused: connect
code :
import java.rmi.*;
import java.net.*;
import java.rmi.registry.*;
class client
{
public static void main(String [] ars)
{
Iface serv;
Registry r;
String serveraddr = ars[0];
String serverport = ars[1];
String text = "Hey jude";
System.out.println("Sending" + text);
try{
r = LocateRegistry.getRegistry(
serveraddr,
(new Integer(serverport)).intValue()
);
serv = (Iface) r.lookup("rmi://server");
serv.receive(text);
}
catch(Exception e){
System.out.println(e);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在绑定、重新绑定或查找时遇到这种情况,则说明注册表未运行。如果执行远程调用,请参阅 RMI 常见问题 随 Javadoc 一起提供,如果您运行的是 Linux,还请检查您的 /etc/hosts 文件是否将 127.0.0.1 映射到 localhost,并将您的真实 IP 地址映射到您的真实主机名 - 这是一个某些 Linux 发行版中的常见问题。
If you're getting that on bind, rebind, or lookup, the Registry isn't running. If you get it doing the remote call, see item A.1 in the RMI FAQ supplied with the Javadoc, and if you're running Linux also check that your /etc/hosts file maps 127.0.0.1 to localhost and your real ip address to your real hostname - this has been a common problem in some Linux distributions.
我遇到了同样的问题。这很愚蠢,只是我忘记启动 RMI 注册表进程。
,您还需要运行 RMI 注册表进程。
因此,在尝试使用 RMI 注册表重新绑定(地址,obj)之前
I met the same problem. It's silly but just that I forgot to start the RMI registry process.
So, you also need to run RMI Registry process
Before you try to rebind(address, obj) with RMI registry.