日期:2014-05-20 浏览次数:20702 次
server = new Socket(InetAddress.getLocalHost(), 3134);
System.out.println(InetAddress.getLocalHost());
BufferedReader in = new BufferedReader(new InputStreamReader(
server.getInputStream()));
PrintWriter out = new PrintWriter(server.getOutputStream());
while (true) {
System.out.print("客户端:");
BufferedReader wt = new BufferedReader(new InputStreamReader(System.in));
String str = wt.readLine();
out.println("客户端:"+str);
out.flush();
if (str.equals("end")) {
out.println("客户端申请退出!"); //前面print加了ln
//这里打印不出来!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
break;
}
System.out.println(in.readLine());
}
server.close();
}
ServerSocket server = new ServerSocket(3134);
Socket client = server.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(
client.getInputStream()));
PrintWriter out = new PrintWriter(client.getOutputStream());
while (true) {
String str = in.readLine();
System.out.println(str);
out.print("has receive...."); //加了ln后 后面的输出打印不出来
//即:out.println("服务器:"+s);内容打印不出!!!!!!!!!!!!!!!!!!!!!!!!!!!
System.out.print("服务器:");
BufferedReader br = new BufferedReader(new InputStreamReader(
System.in));
String s=br.readLine();
out.println("服务器:"+s);
out.flush();
if (str.equals("end")||s.equals("end"))
break;
}
client.close();
}