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);

}

上一篇:让人失望透顶的 CSDN 博客改版


下一篇:C#语言基础— 输入与输出