Example #1
0
 /**
  * Sends one block of a file to the client.
  *
  * @param Client  $client      Client
  * @param integer $piece_index Index of the piece containing the block.
  * @param integer $block_begin Beginning of the block relative
  *                             to the piece in bytes.
  * @param integer $length      Length of the block in bytes.
  *
  * @return void
  */
 protected function sendBlock(Client $client, $piece_index, $block_begin, $length)
 {
     $message = pack('CNN', 7, $piece_index, $block_begin) . $client->getTorrent()->readBlock($piece_index, $block_begin, $length);
     $client->socketWrite(pack('N', strlen($message)) . $message);
     // Saving statistics.
     $client->addStatBytes($length, Client::STAT_DATA_SENT);
 }