java rmi 超时_Java RMI Connect异常:连接拒绝主机/超时

测试您的1099端口是否可用.此外,您没有提到您正在使用的操作系统,以及您是否在执行服务器之前启动了注册表.

这个RMI tutorial解释说:

Before starting the compute engine, you need to start the RMI

registry. The RMI registry is a simple server-side bootstrap naming

facility that enables remote clients to obtain a reference to an

initial remote object.

默认情况下,注册表在端口1099上运行,与您的一样.

在教程报告中,只需打开命令提示符(在Windows上)或shell终端(在类UNIX操作系统上)并键入:

对于Windows(如果启动不可用则使用javaw):

start rmiregistry

Solaris OS或Linux:

rmiregistry &

UPDATE

我注意到,遵循Oracle的教程和我之前的项目,在Server类中,您没有将对象导出到RMI运行时.

然后你应该编辑这些行:

Controle obj = new Controle(4);

Registry reg = LocateRegistry.createRegistry(1099);

System.out.println("Server is ready");

reg.rebind("CtrlServ", obj);

至:

Controle obj = new Controle(4);

Controle stub = (Controle) UnicastRemoteObject.exportObject(obj, 0);

Registry reg = LocateRegistry.createRegistry(1099);

System.out.println("Server is ready");

reg.rebind("CtrlServ", stub);

因为教程报告:

The static UnicastRemoteObject.exportObject method exports the

supplied remote object so that it can receive invocations of its

remote methods from remote clients.

此外,如果您使用相同的主机进行RMI调用,则Client类中不需要它:

Registry registry = LocateRegistry.getRegistry("localhost");

只需调用:

Registry registry = LocateRegistry.getRegistry();

因为Oracle报告:

The no-argument overload of LocateRegistry.getRegistry synthesizes a reference to a registry on the local host and on the default registry port, 1099. You must use an overload that has an int parameter if the registry is created on a port other than 1099.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值