请大家帮忙看一下下面的程序哪里有问题,可以输出“debug 1 ...” ,但无法输出"debug 2 ..." , ip 地址没错- class TcpClient2{
- public static void main(String[] args) throws Exception{
- System.out.println("clint start...");
- Socket s = new Socket("192.168.1.2",10005);
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
- String sendDataStr=null;
- while((sendDataStr=br.readLine())!=null){
- if(sendDataStr.equals("bye")){
- break;
- }
- bw.write(sendDataStr);
- bw.flush();
- }
- bw.close();
- }
- }
- class TcpServer2{
- public static void main(String[] args) throws Exception{
- System.out.println("server start...");
- ServerSocket ss = new ServerSocket(10005);
- Socket s = ss.accept();
- BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
- String receiveDataStr=null;
- System.out.println("debug 1 ...");
- while((receiveDataStr=br.readLine())!=null){
- System.out.println("debug 2 ...");
- if(receiveDataStr.equals("bye")){
- break;
- }
- System.out.println("receive data:"+receiveDataStr);
- }
- s.close();
- ss.close();
- }
- }
复制代码 |
|