直接上代码片段:
out.writeShort(magicAndFlags);
System.out.println("====================================当前数据的字节树" +byteStream.toByteArray().length);
//我们度知道候选ID将会在0到1000之间
out.write((short) msg.getCandidateID());
out.flush();
byte[] data = byteStream.toByteArray();
System.out.println("====================================当前数据的字节树" +data.length);
结果:
====================================当前数据的字节树2
====================================当前数据的字节树3
发送请求 ( 3 bytes :
inquiry for candidate 888
====================================当前数据的字节树2
====================================当前数据的字节树3
发送投票( 3 bytes) :
如果将第二write改成writeShort
out.writeShort(magicAndFlags);
System.out.println("====================================当前数据的字节树" +byteStream.toByteArray().length);
//我们度知道候选ID将会在0到1000之间
out.writeShort((short) msg.getCandidateID());
out.flush();
byte[] data = byteStream.toByteArray();
System.out.println("====================================当前数据的字节树" +data.length);
return data;
Received message (4 bytes
服务器端读取的数据为:response to inquiry for candidate 888 who now has 0 vote(s)
====================================当前数据的字节树2
====================================当前数据的字节树4
Received message (4 bytes
服务器端读取的数据为:response to vote for candidate 888 who now has 1 vote(s)
====================================当前数据的字节树2
====================================当前数据的字节树4