Two quotes:
All other messages in the protocol take the form <length prefix><message ID><payload>. The length prefix is the four-byte value of a large number. The message identifier is one decimal byte. The payload depends on the message.request: <len=0013><id=6><index><begin><length> The request message is a fixed length and is used to request a block. The payload contains the following information:index: an integer specifying the index of pieces based on zerobegin: an integer indicating the byte offset based on zero inside the fragmentlength: an integer specifying the desired length.
All other messages in the protocol take the form <length prefix><message ID><payload>. The length prefix is the four-byte value of a large number. The message identifier is one decimal byte. The payload depends on the message.
<length prefix><message ID><payload>
request: <len=0013><id=6><index><begin><length>
The request message is a fixed length and is used to request a block. The payload contains the following information:
When I write everything, it sums up to 5 bytes. Using
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); byteStream.write( 13 ); byteStream.write( 6 ); byteStream.write( index ); byteStream.write( begin ); byteStream.write( length ); message = byteStream.toByteArray();
EDIT: Sorry, I was very angry when I wrote. its bitoral protocol. Using this spec .
write() .
char int, 8- 0xFF.
DataOutputStream (writeInt, writeShort ..), , Integer.reverseBytes() ( Short.reverseBytes()) writeXYZ().
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(byteStream); dout.writeInt( 0x13 ); // L:4 dout.write( 6 ); // L:5 dout.writeShort( index ); // guess, L:7 dout.writeLong( begin ); // >4GB support? L:15 dout.writeInt( length ); // clients accept below to 2^17, L:19 dout.flush(); // to be sure message = byteStream.toByteArray();
. index, begin length. .
index
begin
length
2: , D.Shawley, .
, ... , <index>, <begin> <length>. , 4- , 1- .
<index>
<begin>
<length>
, , , <length>, <length> +5 , <length>. , 1- 0x06. , :
<index><begin><length>
, , , , .
write() . 5 write() 5 .
. write(int b).
write(int b)
. , . b. 24 b .OutputStream .: b - .
. , . b. 24 b .
OutputStream .
OutputStream
: b - .
Source: https://habr.com/ru/post/1711300/More articles:Reading in Malformed XML (non-encoded XML objects) using PHP - xmlJavascript aliases - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1711297/what-do-you-prefer-for-showing-your-local-rails-projects-to-friends&usg=ALkJrhiNqbgeIsQETZwnMel9vfU625VwxQWhere to store common features in ColdFusion - coldfusionIn XS, how do I get the address of variables from its name? - perlВертикальный текст в службах Reporting Services (снизу вверх) - reporting-services"#if DEBUG" on an ASPX / ASCX page - preprocessorHow do I call managed .NET code from my unmanaged C ++ code on Windows and vice versa? - c ++Is it possible to create a web chat client without socket-based frames? - twistedDatabase programming concepts - designAll Articles