public void run() {
while (true) {
try {
dataInputStream = new DataInputStream(socket.getInputStream());
if (dataInputStream.available()<4) {
continue;

int length =dataInputStream.readByte() + dataInputStream.readByte()*256;
dataInputStream.readByte();
dataInputStream.readByte();
byte[] body = new byte[length];
dataInputStream.read(body);
//VarListProbuf.VarList msg = VarListProbuf.VarList.parseFrom(body);
Intent intent = new Intent("com.ny.gmtool");
Bundle buddle = new Bundle();
//buddle.putString("msg", msg.getStrs(3));
//buddle.putSerializable("msg", msg);
buddle.putByteArray("msg", body);
intent.putExtras(buddle);
context.sendBroadcast(intent);
} catch (IOException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}


}
}代码如上,通讯是用protobuf进行序列化的,当文本中有特殊符号的包,如:\r\n<font color='#FF0000' face='Arial' size='12px'>{0} Not Exist!</font>"
此时读取legth的时候会变为负的,第一次dataInputStream.readByte() 也是负值,导致我计算包长时会为负
但是如果发正常的文本,没有这些符号的时候是可以发送成功的。请问是什么原因呢socket