<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="36889" data-post-id="36889">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="robinmonjo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/robinmonjo/120/29659_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  robinmonjo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Interesting post, how would you write the PHP part in Elixir. I actually need it <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<pre><code>:ok = :gen_tcp.send(socket, payload)
</code></pre>
<p>I understood I need to add the size of my payload in the 32 firsts bits of what I send but how would I do that ?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="36889" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/gen-tcp-socket-maximum-number-of-bytes-characters-possible-to-receive/4618/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-36889" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="36889"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #21"></div>
  </section>
</div>
    <div class="postbit" id="36892" data-post-id="36892">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="robinmonjo" data-post="22" data-topic="4618">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/robinmonjo/48/29659_2.png" class="avatar"> robinmonjo:</div>
<blockquote>
<p>I understood I need to add the size of my payload in the 32 firsts bits of what I send but how would I do that ?</p>
</blockquote>
</aside>
<p>As I recall if you set <code>{packet, 4}</code> in the connect then when you <code>:gen_tcp.send/2</code> it then it should add it automatically.  If however you want to do it manually (like you did not specify a packet option at all then you could do:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">payload = :erlang.iolist_to_binary(payload) # Do this if it is not already a binary
:ok = :gen_tcp.send(socket, [&lt;&lt;byte_size(payload)::integer-size(32)&gt;&gt;, payload])
</code></pre>
<p>Most Erlang IO functions take IO lists, so that is that above.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>You can also bake it into the payload binary itself, but this is slower as it has to copy the entire payload (assuming it is a binary and not an IOlist too):</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">:ok = :gen_tcp.send(socket, &lt;&lt;byte_size(payload)::integer-size(32), payload::binary&gt;&gt;)
</code></pre>
<p><img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji only-emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="36892" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/gen-tcp-socket-maximum-number-of-bytes-characters-possible-to-receive/4618/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-36892" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="36892"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="36899" data-post-id="36899">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="robinmonjo" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/robinmonjo/120/29659_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  robinmonjo
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thank you very much !! Indeed I used <code>packet: :line</code> at the beginning and forgot to change it in the <code>connect</code> options <img src="https://forum.elixirforum.com/images/emoji/apple/blush.png?v=15" title=":blush:" class="emoji" alt=":blush:" loading="lazy" width="20" height="20"></p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="36899" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/gen-tcp-socket-maximum-number-of-bytes-characters-possible-to-receive/4618/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-36899" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="36899"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>