<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Multiplayer on lwcas</title><link>https://lwcasgc.github.io/lwcas/tags/multiplayer/</link><description>Recent content in Multiplayer on lwcas</description><generator>Hugo -- gohugo.io</generator><language>en-US</language><managingEditor>lwcasgc@gmail.com (lwcas)</managingEditor><webMaster>lwcasgc@gmail.com (lwcas)</webMaster><copyright>lwcas</copyright><lastBuildDate>Mon, 10 Nov 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://lwcasgc.github.io/lwcas/tags/multiplayer/index.xml" rel="self" type="application/rss+xml"/><item><title>packets in online games</title><link>https://lwcasgc.github.io/lwcas/programming/packes_in_games/</link><pubDate>Mon, 10 Nov 2025 00:00:00 +0000</pubDate><author>lwcasgc@gmail.com (lwcas)</author><guid>https://lwcasgc.github.io/lwcas/programming/packes_in_games/</guid><description>&lt;h1 id="what-are-packets-in-multiplayer-games"&gt;what are packets in multiplayer games?&lt;/h1&gt;
&lt;p&gt;in multiplayer games, packets are like the envelopes or messages that carry information between players&amp;rsquo; devices and the game server. they ensure that actions like moving your character, shooting, or chatting are synchronized across all players in real-time. without packets, online gaming would be impossible—everyone would be playing in their own isolated world.&lt;/p&gt;
&lt;p&gt;imagine you&amp;rsquo;re playing a team-based game with friends:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;server:&lt;/strong&gt; the central hub that knows everything happening in the game world.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;clients:&lt;/strong&gt; each player&amp;rsquo;s device, sending updates to the server and receiving updates from others.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;packets:&lt;/strong&gt; the data bundles that travel over the internet, containing things like &amp;ldquo;player x moved to position (10, 20)&amp;rdquo; or &amp;ldquo;player y fired a bullet.&amp;rdquo;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;packets make sure everyone sees the same game state, even with network delays or losses. but if packets get lost or arrive out of order, it can cause glitches like rubber-banding or desyncs.&lt;/p&gt;</description><content:encoded><![CDATA[<h1 id="what-are-packets-in-multiplayer-games">what are packets in multiplayer games?</h1>
<p>in multiplayer games, packets are like the envelopes or messages that carry information between players&rsquo; devices and the game server. they ensure that actions like moving your character, shooting, or chatting are synchronized across all players in real-time. without packets, online gaming would be impossible—everyone would be playing in their own isolated world.</p>
<p>imagine you&rsquo;re playing a team-based game with friends:</p>
<ul>
<li><strong>server:</strong> the central hub that knows everything happening in the game world.</li>
<li><strong>clients:</strong> each player&rsquo;s device, sending updates to the server and receiving updates from others.</li>
<li><strong>packets:</strong> the data bundles that travel over the internet, containing things like &ldquo;player x moved to position (10, 20)&rdquo; or &ldquo;player y fired a bullet.&rdquo;</li>
</ul>
<p>packets make sure everyone sees the same game state, even with network delays or losses. but if packets get lost or arrive out of order, it can cause glitches like rubber-banding or desyncs.</p>
<h2 id="how-packets-work-in-practice">how packets work in practice</h2>
<p>packets are sent using network protocols, mainly tcp and udp:</p>
<ul>
<li><strong>tcp (transmission control protocol):</strong> reliable but slower. it guarantees packets arrive in order and retransmits lost ones. used for important data like login info or inventory changes.</li>
<li><strong>udp (user datagram protocol):</strong> fast but unreliable. packets might get lost, but no waiting for retransmission. used for real-time actions like movement updates.</li>
</ul>
<p>in games, a mix is often used. for example, movement might use udp for speed, while chat messages use tcp for reliability.</p>
<p>simple packet example (conceptual, not actual code):</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="ln">1</span><span class="cl"><span class="c1">// imagine sending a position update
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="c1"></span><span class="kd">let</span><span class="w"> </span><span class="n">position_packet</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Packet</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="w">    </span><span class="n">player_id</span>: <span class="mi">1</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="ln">4</span><span class="cl"><span class="w">    </span><span class="n">x</span>: <span class="mf">100.0</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="ln">5</span><span class="cl"><span class="w">    </span><span class="n">y</span>: <span class="mf">200.0</span><span class="p">,</span><span class="w">
</span></span></span><span class="line"><span class="ln">6</span><span class="cl"><span class="w">    </span><span class="n">timestamp</span>: <span class="nc">get_current_time</span><span class="p">(),</span><span class="w">
</span></span></span><span class="line"><span class="ln">7</span><span class="cl"><span class="w"></span><span class="p">};</span><span class="w">
</span></span></span><span class="line"><span class="ln">8</span><span class="cl"><span class="w"></span><span class="n">send_to_server</span><span class="p">(</span><span class="n">position_packet</span><span class="p">);</span></span></span></code></pre></div><p>on the server, it processes and broadcasts to other players:</p>





<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-rust" data-lang="rust"><span class="line"><span class="ln">1</span><span class="cl"><span class="c1">// server receives and relays
</span></span></span><span class="line"><span class="ln">2</span><span class="cl"><span class="c1"></span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Ok</span><span class="p">(</span><span class="n">packet</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">receive_from_client</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="ln">3</span><span class="cl"><span class="w">    </span><span class="n">broadcast_to_all_clients</span><span class="p">(</span><span class="n">packet</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="ln">4</span><span class="cl"><span class="w"></span><span class="p">}</span></span></span></code></pre></div><h2 id="why-packet-handling-matters">why packet handling matters</h2>
<p>poor packet management can ruin the experience:</p>
<ul>
<li><strong>latency (ping):</strong> time for a packet to go to the server and back. high latency causes delays in actions.</li>
<li><strong>packet loss:</strong> some packets don&rsquo;t arrive. games interpolate missing data to smooth it out.</li>
<li><strong>jitter:</strong> inconsistent delays. causes stuttering.</li>
<li><strong>security:</strong> packets can be spoofed or tampered with, so games use encryption and validation.</li>
</ul>
<p>these issues are why games have &ldquo;netcode&rdquo; – the system handling network communication. good netcode predicts movements and corrects errors to keep the game fair and fun.</p>
<h2 id="extras">extras</h2>
<p><strong>dead reckoning:</strong> predicting player positions based on last known data to hide latency. like assuming a car keeps moving straight until new info arrives.</p>
<p><strong>rollback netcode:</strong> rewinding time to correct mistakes from lost packets, used in fighting games for precise timing.</p>
]]></content:encoded></item></channel></rss>