0
我總是收到消息不知道主人:taranis。同時運行echoclient程序。這裏是低於關於Echoclient程序的問題
import java.io.*;
import java.net.*;
public class EchoClient {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
echoSocket = new Socket("taranis",3218);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: taranis.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for "
+ "the connection to: taranis.");
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();
}
}
taranis是誰?你的網絡中有這臺計算機嗎? – MByD 2011-05-01 06:04:21
呃,好吧......這意味着沒有像「taranis」這樣的主持人。您需要使用有效的主機名。 – 2011-05-01 06:04:50
僅供參考:此代碼似乎來自這裏:http://download.oracle.com/javase/tutorial/networking/sockets/readingWriting.html – icktoofay 2011-05-01 06:07:27