# Error in order of extension handshake messages and wrong byte order in length field of extension handshake request message

**URL:** <https://forum.codecrafters.io/t/error-in-order-of-extension-handshake-messages-and-wrong-byte-order-in-length-field-of-extension-handshake-request-message/4778>\
**Category:** Challenges\
**Tags:** challenge:bittorrent\
**Created:** [February 10, 2025, 2:47am UTC](https://forum.codecrafters.io/t/error-in-order-of-extension-handshake-messages-and-wrong-byte-order-in-length-field-of-extension-handshake-request-message/4778 "2025-02-10T02:47:25Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [February 27, 2025, 9:03am UTC](https://forum.codecrafters.io/t/error-in-order-of-extension-handshake-messages-and-wrong-byte-order-in-length-field-of-extension-handshake-request-message/4778/8 "2025-02-27T09:03:21Z")

</div>

- **Order of the extension handshake request/response** ,

The order shouldn’t matter. Either peer can send the handshake first. [Here’s a related explanation](https://forum.codecrafters.io/t/confusion-regarding-stage-xi4/2944/3) that might help clarify.

* * *

The issue seems to be caused by `clearReadBuffer`:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/1/1c7d97c2bc740fc0e88f851dfab0cc0facb60ef6.png)

I’m not sure why it’s there, but if I comment it out, and rearrange `doExtendedHandshake`, your code still works:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/a/a7837be05f5fcbff93d1ec1c00aaa9a2bc390c17.png)

Let me know if you’d like further assistance!

---

_[View the full topic](https://forum.codecrafters.io/t/error-in-order-of-extension-handshake-messages-and-wrong-byte-order-in-length-field-of-extension-handshake-request-message/4778)._
