package cn.soft.socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
public class TransClientDemo {
/**
* @param args
* @throws IOException
* @throws UnknownHostException
*/
public static void main(String[] args) throws UnknownHostException, IOException {
Socket s=new Socket("127.0.0.1",10005);//创建客户端窗口
BufferedReader bufr=new BufferedReader(new InputStreamReader(System.in));//读取键盘输入
PrintWriter out=new PrintWriter(s.getOutputStream(),true);//socket输出流
BufferedReader bufrin=new BufferedReader(new InputStreamReader(s.getInputStream()));
String line=null;
while ((line=bufr.readLine())!=null) {
if ("over".equals(line)) {
break;
}
out.println(line);
String upperStr=bufrin.readLine();
System.out.println(upperStr);
}
s.close();
}
}
有这样一个问题 如果我这行里不用自动刷新PrintWriter out=new PrintWriter(s.getOutputStream(),true);//socket也就是不加true,然后在最后加个out.flush();为什么达不到同样的效果,这是为何,用true就没问题会自动刷新 |