Two quotes:
All of the remaining messages in the protocol take the form of
<length prefix><message ID><payload>
. The length prefix is a four byte big-endian value. The message ID is a single decimal byte. The payload is message dependent.request: <len=0013><id=6><index><begin><length>
The request message is fixed length, and is used to request a block. The payload contains the following information:
- index: integer specifying the zero-based piece index
- begin: integer specifying the zero-based byte offset within the piece
- length: integer specifying the requested length.
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 kind of pissed when i wrote it. its the bittorent protocol. Using this spec.