概述
我正在尝试学习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正常工作所需的代码.有人有解释吗?
最后
以上就是眯眯眼抽屉为你收集整理的java rmi重要吗_java – 在localhost上拒绝RMI连接的全部内容,希望文章能够帮你解决java rmi重要吗_java – 在localhost上拒绝RMI连接所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复