java rmi重要吗_java – 在localhost上拒绝RMI连接

我正在尝试学习RMI编码,当我运行RMI的服务器端时,我得到连接拒绝.

这是我的服务器主要方法

public static void main(String[] args)throws Exception {

Implementation impl=new Implementation();

Naming.rebind("//localhost:2020/RMI", impl);

System.out.println("Implementation has been bind to the name RMI and is ready for use");

}

我相信实现的代码并不重要,因为它只是运行代码的实现接口.我得到的例外就是这个

Exception in thread "main" java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:

java.net.ConnectException: Connection refused: connect

at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)

at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source)

at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)

at sun.rmi.server.UnicastRef.newCall(Unknown Source)

at sun.rmi.registry.RegistryImpl_Stub.rebind(Unknown Source)

at java.rmi.Naming.rebind(Unknown Source)

at epl362Project.Server.main(Server.java:10)

Caused by: java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

at java.net.PlainSocketImpl.connect(Unknown Source)

at java.net.SocksSocketImpl.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.connect(Unknown Source)

at java.net.Socket.(Unknown Source)

at java.net.Socket.(Unknown Source)

at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)

at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)

... 7 more

我究竟做错了什么?客户端和服务器端都将在我的笔记本电脑上运行,因为这只是一个练习.我错过了什么或者我的代码有问题吗?请除了给我答案解释为什么会这样,因为我不想让它成功,我正在努力学习.

**编辑

我发现了为什么我的代码无效.我错过了一行代码说

LocateRegistry.createRegistry(2020);

我从stackoverflow上的其他问题中找到了.但是没有解释,也没有在网上找到为什么RMI正常工作所需的代码.有人有解释吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值