0
运行下面的代码给予例外:无法连接到端口7
d:\书籍\教程\网络\插座\实例>的Java EchoClient 拒绝连接:连接
这实际上是从java教程的代码(从oracle) 我甚至尝试从防火墙打开icmp eco请求,任何人都可以解释为什么这是哈特?我正在使用Windows 7 32位
import java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String[] args) throws Exception {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("localhost", 7);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (Exception e) {
System.err.println(e.getMessage());
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(
new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}
嘿,我读了端口7是回声端口的地方,我甚至尝试添加防火墙例外,但它仍然不工作 – lol
我修改了我的答案 - 也许麻烦的是,你没有配置回声服务。 –
k如何配置呢? – lol