<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Agnostic on AI VOID</title><link>https://ai-blog.noorshomelab.dev/tags/agnostic/</link><description>Recent content in Agnostic on AI VOID</description><generator>Hugo</generator><language>en</language><lastBuildDate>Wed, 20 Aug 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://ai-blog.noorshomelab.dev/tags/agnostic/index.xml" rel="self" type="application/rss+xml"/><item><title>Chapter 5: Managing Active WebSocket Connections</title><link>https://ai-blog.noorshomelab.dev/chat-guide/chapter-5-connection-manager/</link><pubDate>Wed, 20 Aug 2025 00:00:00 +0000</pubDate><guid>https://ai-blog.noorshomelab.dev/chat-guide/chapter-5-connection-manager/</guid><description>&lt;p&gt;Our current WebSocket endpoint only echoes messages back to the sender. A real chat application needs to handle multiple users, allowing them to join, leave, and send messages that are broadcast to all other connected users (or users in a specific room). This chapter introduces a WebSocket connection manager to address this.&lt;/p&gt;
&lt;h3 id="purpose-of-this-chapter"&gt;Purpose of this Chapter&lt;/h3&gt;
&lt;p&gt;By the end of this chapter, you will:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Understand the need for a connection manager in a real-time application.&lt;/li&gt;
&lt;li&gt;Implement a &lt;code&gt;ConnectionManager&lt;/code&gt; class to store and manage active WebSocket connections.&lt;/li&gt;
&lt;li&gt;Modify the WebSocket endpoint to use the manager for connecting, disconnecting, and broadcasting messages.&lt;/li&gt;
&lt;li&gt;Test broadcasting functionality with multiple client connections.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id="concepts-explained-connection-management"&gt;Concepts Explained: Connection Management&lt;/h3&gt;
&lt;p&gt;When a client connects via WebSocket, the &lt;code&gt;WebSocket&lt;/code&gt; object represents that specific connection. To send a message to all active clients, or a subset of them, our server needs a way to keep track of these individual &lt;code&gt;WebSocket&lt;/code&gt; objects. A &lt;code&gt;ConnectionManager&lt;/code&gt; class typically serves this purpose.&lt;/p&gt;</description></item></channel></rss>