java.net.ConnectException:连接超时:连接?

发布于 2024-11-01 06:21:05 字数 2046 浏览 2 评论 0原文

我在我的代码中使用了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

焚却相思 2024-11-08 06:21:05

错误消息说明了一切:您的连接超时。这意味着您的请求在某个(默认)时间范围内没有得到响应。未收到响应的原因可能是以下之一:

  • a) IP/域或端口不正确
  • b) IP/域或端口(即服务)已关闭
  • c) IP/域花费的时间比默认值长响应超时
  • d) 您的防火墙阻止了您正在使用的任何端口上的请求或响应
  • e) 您的防火墙阻止了对该特定主机的请求
  • f) 您的互联网访问已关闭

请注意防火墙和端口或 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:

  • 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

Note that firewalls and port or IP blocking may be in place by your ISP

云柯 2024-11-08 06:21:05

数字 (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.

你怎么这么可爱啊 2024-11-08 06:21:05

异常: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:

  • Too many requests overloading the server
  • Request packet loss because of wrong network configuration or line overload
  • Sometimes firewall consume request packet before sever getting
  • Also depends on thread connection pool configuration and current status of connection pool
  • Response packet lost during transition
想你的星星会说话 2024-11-08 06:21:05

如果您将配置指向某个域(例如 fabrikam.com),请执行 NSLOOKUP 以确保所有响应 IP 均有效,并且可以连接到端口 389:

NSLOOKUP fabrikam.com

Test-NetConnection <IP returned from NSLOOKUP> -port 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:

NSLOOKUP fabrikam.com

Test-NetConnection <IP returned from NSLOOKUP> -port 389
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文