解决java.net.ConnectException: Connection refused: connect

查阅资料,在外网上即一篇解决方法

3. How to solve Connect Exception

Following the directives of the above paragraphs, there are one or two things that you can check when you come across a java.net.ConnectException.

  1. Check the client configuration: That involves checking whether the client is trying to connect to the correct IP address and the correct port. For more complex connection, for example if you are trying to make an RMI (Remote Method Invocation) call, you should check if you are using the correct protocol, port and IP in the connection String. Same goes if you’re trying to connect to a MySQL server via JDBC.
  2. Check the server configuration: That involves checking whether the server can actually listen to the port that the client tries to connect to.
  3. Make sure that the server is up and running: Although all your configurations are fine, your server application might have crushed and stopped, and therefore it is down.
  4. Check if the remote client or server are connected to the net: You have to make sure that both machines are accessible in the network you are working on. Whether this is the same host (localhost), or your home network which means that both of the machines have to be connected to the same router (or be accessible by one another anyway), or it is a company network which means that both machines have to have access to he company network, or if its a completely remote connection then both machines have to have Internet access. In sum, make sure that the hosts that run your client and server application are accessible by one another.
  5. Check firewall configurations: This is a very common source of java.net.ConnectException. If you are trying to connect to a remote host that you know is running and you have all the configurations correct but you still get that exceptions, chances are that the remote server host blocks this port with a firewall. For example, it might only allow local connection to that port, but not remote connections. or might only allow specific IPs to connect to the port etc. Furthermore it is highly possible that your own network cannot allow that connection. For example if you stand behind your company network and you try to connect to a remote server, it is possible that your company’s router will block the connection.

总结就是,检查客户端配置,检查服务器端配置,确定服务器端起来并且能运行,检查是否联网,检查防火墙配置。

总结就是五点,希望可以帮助大家!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java.net.ConnectException: Connection refused: connect是一个常见的网络连接异常错误,它表示在尝试建立连接时,目标主机拒绝了连接请求。这可能是由于以下几个原因引起的: 1. 目标主机未启动或未监听指定的端口。 2. 防火墙或网络配置阻止了连接。 3. 目标主机上的服务未正确配置或未运行。 解决这个问题的方法取决于具体的情况。以下是一些常见的解决办法: 1. 确保目标主机已启动并正在监听指定的端口。可以使用telnet命令或其他网络工具来测试连接是否正常。 2. 检查防火墙或网络配置,确保允许连接到目标主机的指定端口。如果有防火墙或网络设备,需要相应地配置它们以允许连接。 3. 检查目标主机上的服务是否正确配置和运行。确保服务已启动并监听正确的端口。 4. 如果使用的是FinalShell连接Linux虚拟机,并且出现了java.net.ConnectException: Connection refused: connect错误,可以尝试以下解决办法: - 确保Linux虚拟机已启动并正在运行。 - 检查Linux虚拟机的网络配置,确保网络连接正常。 - 检查FinalShell的连接配置,确保已正确配置主机地址和端口。 - 确保Linux虚拟机上的服务已正确配置和运行。 总之,要解决java.net.ConnectException: Connection refused: connect错误,需要检查目标主机的状态、网络配置和服务配置,并确保它们都正确运行。如果问题仍然存在,可能需要进一步调试和排查。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值