java Socket 使用注意
1 Socket s = new Socket(ia, port); 2 3 BufferedOutputStream bufOut = new BufferedOutputStream(s.getOutputStream()); 4 5 byte[] bytes = logXml.getBytes(CHARSET); 6 7 bufOut.write(bytes); 8 9 // 因为下边还要使用getInputStream,所以此处不可以使用bufOut.close() 10 11 bufOut.flush(); //此处必须flush 12 13 s.shutdownOutput(); 14 15 BufferedReader bufin = new BufferedReader(new InputStreamReader(s.getInputStream(), CHARSET)); 16 17 String line = null; 18 19 while (null != (line = bufin.readLine())) 20 21 { 22 23 System.out.println(line); 24 25 }