java.net.ConnectException:连接超时:连接?
我在我的代码中使用了 RMI :
import java.rmi.*;
public interface AddServerIntf extends Remote {
double add(double d1,double d2) throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf {
public AddServerImpl() throws RemoteException {
}
public double add(double d1,double d2) throws RemoteException {
return d1+d2;
}
}
import java.net.*;
import java.rmi.*;
public class AddServer {
public static void main(String args[]) {
try {
AddServerImpl addServerImpl=new AddServerImpl();
Naming.rebind("AddServer",addServerImpl);
} catch(Exception exc) {
System.out.println(exc);
}
}
}
import java.rmi.*;
public class AddClient {
public static void main(String args[]) {
try {
String Url="rmi://"+args[0]+"/AddServer";
AddServerIntf addServerIntf=(AddServerIntf)Naming.lookup(Url);
System.out.println("The first number is "+args[1]);
double d1=Double.valueOf(args[1]).doubleValue();
System.out.println("The second number is: "+args[2]);
double d2=Double.valueOf(args[2]).doubleValue();
System.out.println("The Sum is: "+addServerIntf.add(d1,d2));
} catch(Exception exc) {
System.out.println(exc);
}
}
}
这些是编写的 4 个 .java 文件。
接下来,我编译所有这些文件。然后我使用 rmic AddServerImpl
创建一个 stub
。之后,我使用 start rmiregistry
在服务器端启动 rmi 注册表。然后我使用 java AddServer
启动服务器,最后使用 java AddClient 27.60.200.80 5 9
启动客户端。 但是没有任何反应
客户端抛出的异常是java.net.ConnectException:连接超时:连接
原因是什么以及如何解决我解决这个问题吗?
在客户端计算机上,这些是以下 .class 文件 AddClient.class AddServerImpl.class AddServerImpl_Stub.class
和在服务器端 AddServer.class AddServerImpl.class AddServerImpl_Stub.class AddServerIntf.class
I have used RMI in my code :
import java.rmi.*;
public interface AddServerIntf extends Remote {
double add(double d1,double d2) throws RemoteException;
}
import java.rmi.*;
import java.rmi.server.*;
public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf {
public AddServerImpl() throws RemoteException {
}
public double add(double d1,double d2) throws RemoteException {
return d1+d2;
}
}
import java.net.*;
import java.rmi.*;
public class AddServer {
public static void main(String args[]) {
try {
AddServerImpl addServerImpl=new AddServerImpl();
Naming.rebind("AddServer",addServerImpl);
} catch(Exception exc) {
System.out.println(exc);
}
}
}
import java.rmi.*;
public class AddClient {
public static void main(String args[]) {
try {
String Url="rmi://"+args[0]+"/AddServer";
AddServerIntf addServerIntf=(AddServerIntf)Naming.lookup(Url);
System.out.println("The first number is "+args[1]);
double d1=Double.valueOf(args[1]).doubleValue();
System.out.println("The second number is: "+args[2]);
double d2=Double.valueOf(args[2]).doubleValue();
System.out.println("The Sum is: "+addServerIntf.add(d1,d2));
} catch(Exception exc) {
System.out.println(exc);
}
}
}
These are 4 .java files written.
Next i compile all these files.Then I create a stub
using rmic AddServerImpl
. After that i start rmi registry on server side using start rmiregistry
. Then i start server using java AddServer
and finally client using java AddClient 27.60.200.80 5 9
.
But nothing happens
Exception that is thrown on client side is java.net.ConnectException : connection timed out : connect
What is the reason and how can i solve this?
On client machine these are the following .class files AddClient.class AddServerImpl.class AddServerImpl_Stub.class
and on server side AddServer.class AddServerImpl.class AddServerImpl_Stub.class AddServerIntf.class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
错误消息说明了一切:您的连接超时。这意味着您的请求在某个(默认)时间范围内没有得到响应。未收到响应的原因可能是以下之一:
请注意防火墙和端口或 IP 阻止可能由您的 ISP 设置
The error message says it all: your connection timed out. This means your request did not get a response within some (default) timeframe. The reasons that no response was received is likely to be one of:
Note that firewalls and port or IP blocking may be in place by your ISP
数字 (1):IP 不正确 - 是正确答案。 /etc/hosts 文件(又名
C:\Windows\system32\drivers\etc\hosts ) 的本地计算机名称条目不正确。
更正了“hosts”文件,Camel 运行得很好。谢谢指点。
Number (1): The IP was incorrect - is the correct answer. The /etc/hosts file (a.k.a.
C:\Windows\system32\drivers\etc\hosts ) had an incorrect entry for the local machine name.
Corrected the 'hosts' file and Camel runs very well. Thanks for the pointer.
异常:java.net.ConnectException
这意味着您的请求没有在规定的时间内从服务器获得响应。造成此异常的原因有:
Exception : java.net.ConnectException
This means your request didn't getting response from server in stipulated time. And their are some reasons for this exception:
如果您将配置指向某个域(例如 fabrikam.com),请执行 NSLOOKUP 以确保所有响应 IP 均有效,并且可以连接到端口 389:
If you're pointing the config at a domain (eg fabrikam.com), do an NSLOOKUP to ensure all the responding IPs are valid, and can be connected to on port 389: