java.net.ConnectException:连接超时:连接?
我在我的代码中使用了RMI:
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);
}
}
}
这些是4个.java文件写了。
These are 4 .java files written.
接下来我编译所有这些文件。然后我使用 rmic创建
。之后,我使用存根
AddServerImpl start rmiregistry
在服务器端启动rmi注册表。然后我使用 java AddServer
启动服务器,最后使用 java AddClient 27.60.200.80 5 9
启动客户端。
但没有任何反应
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
客户端抛出的异常是 java.net。 ConnectException:连接超时:连接
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?
在客户端计算机上,这些是以下.class文件 AddClient.class AddServerImpl.class AddServerImpl_Stub.class
和服务器端 AddServer.class AddServerImpl.class AddServerImpl_Stub.class AddServerIntf.class
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
错误消息说出来all:你的连接超时了。这意味着您的请求未在某个(默认)时间范围内得到响应。没有收到回复的原因可能是以下之一:
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:
- a)IP /域或端口不正确
- b)IP /域或端口(即服务)已关闭
- c)IP /域的响应时间超过默认超时响应
- d)您的防火墙阻止您正在使用的任何端口上的请求或响应
- e)您的防火墙阻止了对该特定端口的请求主机
- f)您的互联网访问已关闭
- a) The IP/domain or port is incorrect
- b) The IP/domain or port (i.e service) is down
- c) The IP/domain is taking longer than your default timeout to respond
- d) You have a firewall that is blocking requests or responses on whatever port you are using
- e) You have a firewall that is blocking requests to that particular host
- f) Your internet access is down
请注意防火墙和端口或IP阻止可能由您的ISP
Note that firewalls and port or IP blocking may be in place by your ISP