try{
int sumb=0;
int c=0;
ByteArrayOutputStream buffeOut =new ByteArrayOutputStream();
byte readbuf[] = new byte[10240];
while (socket.isConnected() && !socket.isClosed()) {
while ((c = in.read(readbuf)) != -1) {
buffeOut.write(readbuf, 0, c);
sumb =sumb + c;
}
byte[] data =buffeOut.toByteArray();
byte[] hend =new byte[3];
hend[0] =data[0];
hend[1] =data[1];
hend[2] =data[2];
String hh = new String(hend,"utf-8");
String strin = new String(data,"utf-8");//转成约定的编码
System.out.println("读取流数据头: "+hh);
System.out.println("读取流数据内容: "+strin+","+sumb);
buffeOut.reset();
//读完后回复信息.
out.write(("已收到数据!").getBytes("utf-8"));
out.flush();
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
System.out.println("读取流数据完成.");
}