RMI java.rmi.ConnectException: Connection refused to host: 192.168.1.108

具体请参照http://stackoverflow.com/questions/8485239/java-rmi-connect-exception-connection-refused-to-host-timeout

RMI开发时出现这种错误时,可采用如下方式解决:

This RMI tutorial explains:

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.

By default, the registry runs on port 1099, like yours. As the tutorial reports, just open a command prompt (on Windows) or a shell terminal (on a UNIX-like OS) and type:

For Windows (use javaw if start is not available):

start rmiregistry

Solaris OS or Linux:

rmiregistry &

UPDATE

I noticed, following the Oracle's tutorial and a my project of time ago, that in the Server class, you didn't exported the object to the RMI runtime. Then you should edit these lines:

Controle obj = new Controle(4);
Registry reg = LocateRegistry.createRegistry(1099);
System.out.println("Server is ready");
reg.rebind("CtrlServ", obj);

to:

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

Because the tutorial reports:

The static UnicastRemoteObject.exportObject method exports the supplied remote object so that it can receive invocations of its remote methods from remote clients.

Also, if you are using the same host for a RMI invocation, it isn't needed in the Client class:

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

Simply invoke:

Registry registry = LocateRegistry.getRegistry();

Because Oracle reports:

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值