# TCP Requests should be sent in chunks

**URL:** <https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580>\
**Category:** General\
**Tags:** challenge:http-server\
**Created:** [June 1, 2024, 10:15am UTC](https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580 "2024-06-01T10:15:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fre-ros](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/fre-ros/32/528_2.png) [@fre-ros](https://forum.codecrafters.io/u/fre-ros)\
**Post date:** [June 1, 2024, 10:15am UTC](https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580/1 "2024-06-01T10:15:32Z")

</div>

TCP is a stream oriented protocol and multiple calls to recv may be needed to receive a full HTTP request. There should probably be a step in the course where requests starts getting sent in chunks so the server implementations have to handle that.

To ensure this in the test code, disabling the [Nagle algorithm](https://en.wikipedia.org/wiki/Nagle%27s_algorithm) for the TCP connection and making multiple calls to send with a small delay between calls should ensure data is sent in segments.

---

<div class="post-metadata">

**Author:** ![fre-ros](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/fre-ros/32/528_2.png) [@fre-ros](https://forum.codecrafters.io/u/fre-ros)\
**Post date:** [June 1, 2024, 9:35pm UTC](https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580/2 "2024-06-01T21:35:51Z")

</div>

This should probably apply to all courses which uses tcp for communication.

It’s a basic thing that all servers of any kind that uses tcp has to handle, so the tests should be designed to force tcp messages to be fragmented.

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [June 3, 2024, 5:01pm UTC](https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580/3 "2024-06-03T17:01:41Z")

</div>

Yeah, this is a valid point. Our thinking was that we’d make this an extension.

@fre-ros do you think it makes more sense to test for this from the start? Or would you prefer if this was an extension?

---

<div class="post-metadata">

**Author:** ![fre-ros](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/fre-ros/32/528_2.png) [@fre-ros](https://forum.codecrafters.io/u/fre-ros)\
**Post date:** [June 3, 2024, 6:12pm UTC](https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580/4 "2024-06-03T18:12:59Z")

</div>

I guess ideally it would be from the start as it will affect the designed solutions fundamentally, one has to create a state machine for parsing/decoding instead of taking for granted that all necessary data has been received.

But if you change it from the start I guess that will break the solution for many people so an extension is probably better?

---

<div class="post-metadata">

**Author:** ![guhan-balaji](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/guhan-balaji/32/4385_2.png) [@guhan-balaji](https://forum.codecrafters.io/u/guhan-balaji)\
**Post date:** [January 19, 2025, 5:16pm UTC](https://forum.codecrafters.io/t/tcp-requests-should-be-sent-in-chunks/580/5 "2025-01-19T17:16:36Z")

</div>

hello @rohitpaulk, I just started my first codecrafters challenge (http in Go) and I am enjoying it so far. I have noticed streaming is not explicitly a part of the current http extension. Do you still plan on adding it as an extension?

Also, I’ve been trying to understand how TCP handles streaming and I came across this [article](https://www.7onn.dev/post/tcp-connections-and-buffers-in-go/). I am struggling to understand why the output changes the way it does when the buffer size in the server changes to 1. I would appreciate if anyone could explain the final output from the article. Thanks.
