java Socket使用注意

Socket s = new Socket(ia, port); BufferedOutputStream bufOut = new BufferedOutputStream(s.getOutputStream()); byte[] bytes = logXml.getBytes(CHARSET); bufOut.write(bytes); // 因为下边还要使用getInputStream,所以此处不可以使用bufOut.close() bufOut.flush(); //此处必须flush s.shutdownOutput(); BufferedReader bufin = new BufferedReader(new InputStreamReader(s.getInputStream(), CHARSET)); String line = null; while (null != (line = bufin.readLine())) { System.out.println(line); }
posted @ 2016-12-07 16:51  LiuYanYGZ  阅读(204)  评论(0编辑  收藏  举报