客户端读写的阻塞问题,
- import java.io.*;
- import java.net.*;
- class TransClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("192.168.1.102", 10008);
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- PrintWriter bout = new PrintWriter(s.getOutputStream(), true);
- BufferedReader bread = new BufferedReader(new InputStreamReader(s.getInputStream()));
- String line = null;
- while ((line=br.readLine())!=null)
- {
- if ("over".equals(line))
- break;
- bout.println(line);//客户端写数据到网络流中,
- System.out.println(bread.readLine());//客户端读网络流中的数据,如果上一句写完发送到服务器还没等发回,那程序是不是就停止这里等
- }
- br.close();
- bout.close();
- s.close();
- }
- }
复制代码
|
|