[英]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.