简体   繁体   English

如何解决:连接到本地主机时出错:Java中的连接被拒绝

[英]How to fix: Error connecting to localhost: Connection Refused in Java

I am new to java and I am working my way through a few tutorials. 我是Java的新手,并且正在通过一些教程进行学习。 The tutorials don't do much for troubleshooting and I am having troulbe getting one of them to work. 这些教程在故障排除方面并没有做很多事情,我想让它们之一工作。 I am attempting to connect to my localhost server on windows 8. Here is my code: 我正在尝试连接Windows 8上的本地主机服务器。这是我的代码:

import java.net.*;
public class Connect {
   public static void main(String[] args) {
      String server_name = "localhost";

      try {
         Socket sock = new Socket(server_name, 80);

         System.out.println("***Connect to " + server_name + " ***");

         sock.close();

      }

      catch (java.io.IOException e ) {

         System.out.println("Error connect to " + server_name + 
         ": " + e);

         return;
      }
   }
}

and here is my error message when i run the code: 这是我运行代码时的错误消息:

Error connect to localhost: java.net.ConnectException: Connection refused: connect 连接到本地主机时出错:java.net.ConnectException:连接被拒绝:connect

Needed to start my XAMPP Server prior to running the code example. 在运行代码示例之前,需要启动XAMPP服务器。 Thanks all for the help! 谢谢大家的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到本地主机时出错:8060:java.net.ConnectException:连接被拒绝 - Error connecting to localhost:8060: java.net.ConnectException: Connection refused Java Web 项目 + JPA/JDBC“连接到端口 1527 上的服务器本地主机时出错,消息连接被拒绝” - Java web project + JPA/JDBC “Error connecting to server localhost on port 1527 with message Connection refused” 在端口1527上连接到服务器localhost时出错,并显示消息连接被拒绝 - Error connecting to server localhost on port 1527 with message Connection refused Java RMI连接错误:未连接到本地主机 - Java RMI connection error: Not connecting to localhost 从Selenium RemoteWebDriver与Selenium Docker Firefox容器连接时,如何解决“拒绝连接”错误? - How to fix “Connection Refused” error while connecting with Selenium Docker Firefox container from Selenium RemoteWebDriver? 如何修复“nodetool:无法连接到'localhost:7199' - ConnectException:'连接被拒绝(连接被拒绝)'。” - how to fix “nodetool: Failed to connect to 'localhost:7199' - ConnectException: 'Connection refused (Connection refused)'.” 通过Java连接到Remedy时出现错误90(连接被拒绝) - Error 90 (Connection refused) when connecting to Remedy via Java java derby连接到端口1,527上的服务器localhost,消息连接被拒绝 - java derby connecting to server localhost on port 1,527 with message Connection refused 如何修复java.net.ConnectException:在Storm中拒绝连接 - How to fix java.net.ConnectException: Connection refused in Storm 通过 IP 地址而不是 localhost 连接到 RabbitMQ 时连接被拒绝 - Connection refused when connecting to RabbitMQ via IP address instead of localhost
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM