RMI连接在localhost上被拒绝 [英] RMI connection refused on localhost

查看:1986
本文介绍了RMI连接在localhost上被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想学习RMI编码,当我运行服务器端的RMI我得到连接拒绝。
这是我的服务器主方法

I am trying to learn RMI coding and when I run server side of RMI I get connection refused. This is my server main method

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



我相信实现的代码并不重要,因为它只是实现接口将运行代码。我得到的异常是

I believe that the code for Implementation does not matter as it simply is the implemented interface that will run the code. The exception I am getting is this

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.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unknown Source)
    at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unknown Source)
    ... 7 more

我做错了什么?客户端和服务器端都将在我的笔记本电脑上运行,因为这只是一个练习。我缺少的东西或有什么问题的我的代码?除了给我的答案解释为什么是这样,因为我不只是想让它的工作,我想学习。

What am I doing wrong? both client and server sides will run on my laptop as this is just an exercise. Am I missing something or is there something wrong with my code? Please besides giving me the answer explain why it is so since I do not just want to make it work, I am trying to learn.

**编辑
我发现为什么我的代码不工作。我缺少一行代码

**EDIT I found out why my code was not working. I was missing a line of code that said

LocateRegistry.createRegistry(2020);

这是我从stackoverflow的其他问题。但是没有解释,也没有在网上找到为什么这个代码是需要的RMI正常工作。

which I found from other questions here on stackoverflow. But there was no explanation nor did I find one online as to why this code was needed for RMI to work properly. Does anyone have an explanation?

推荐答案

Naming.bind()是RMI注册表。它必须运行。它没有运行。所以你不能连接到它。所以你有一个ConnectException。

The target of Naming.bind() is the RMI registry. It has to be running. It wasn't running. So you couldn't connect to it. So you got a ConnectException.

这篇关于RMI连接在localhost上被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆