Getting EOF after requesting 12 blocks successfully

Hi @arashout, there might be multiple issues at play here. Let’s address the first two I noticed:

  1. Message Length Prefix: The value of the message length prefix should not include itself. Therefore, it should be calculated as length - 4.

  1. Last Piece Length: The code doesn’t account for the fact that the length of the last piece could be shorter than the standard piece length.
  • Example: If the file length is 10 bytes and the piece length is 3 bytes, the last piece would only contain 1 byte instead of the full 3.