刚开始学习java网络编程,在书上看到一段代码,就动手试一下,结果出现下面错误:
java.net.ConnectException: Connection refused: connect
源代码如下:
import java.io.*;
import java.net.*;
class lx01 {
public static void main(String[] args) {
String host = "localhost";
BufferedReader br = null;
PrintWriter pw = null;
Socket s = null;
try {
s = new Socket(host, 10000);
InputStreamReader isr;
isr = new InputStreamReader(s.getInputStream());
br = new BufferedReader(isr);
pw = new PrintWriter(s.getOutputStream(), true);
pw.println("DATE");
System.out.println(br.readLine());
pw.println("PAUSE");
pw.println("DOW");
System.out.println(br.readLine());
pw.println("DOM");
System.out.println(br.readLine());
pw.println("DOY");
System.out.println(br.readLine());
} catch (IOException e) {
System.out.println(e.toString());
} finally {
try {
if (br != null)
br.close();
if (pw != null)
pw.close();
if (s != null)
s.close();
} catch (IOException e) {
}
}
}
}
求教各位大神这是啥原因,如何解决?