<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SikorSky</title>
    <description>The latest articles on DEV Community by SikorSky (@sikorsky43).</description>
    <link>https://dev.to/sikorsky43</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3808426%2F3b6f1f88-cfeb-4f0d-b01e-5d02bdf8a095.jpeg</url>
      <title>DEV Community: SikorSky</title>
      <link>https://dev.to/sikorsky43</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sikorsky43"/>
    <language>en</language>
    <item>
      <title>Building a TCP Group Chat App with JavaFX and Maven</title>
      <dc:creator>SikorSky</dc:creator>
      <pubDate>Thu, 05 Mar 2026 20:19:25 +0000</pubDate>
      <link>https://dev.to/sikorsky43/building-a-tcp-group-chat-app-with-javafx-and-maven-1e46</link>
      <guid>https://dev.to/sikorsky43/building-a-tcp-group-chat-app-with-javafx-and-maven-1e46</guid>
      <description>&lt;h1&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Building a Real-Time Group Chat with Java TCP Sockets and JavaFX&lt;/em&gt;&lt;/strong&gt;
&lt;/h1&gt;

&lt;p&gt;We recently implemented a mini project where the objective was to build a &lt;strong&gt;real-time group chat application&lt;/strong&gt; using &lt;strong&gt;Java TCP sockets&lt;/strong&gt; and &lt;strong&gt;JavaFX&lt;/strong&gt;. This article summarizes the &lt;strong&gt;architecture, design decisions, and lessons learned&lt;/strong&gt; during development.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Project Goal&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The project required implementing a &lt;strong&gt;complete TCP-based chat system&lt;/strong&gt; with the following capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;central TCP server&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Multiple concurrent clients&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Real-time message broadcasting&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;A command to &lt;strong&gt;list active users (&lt;code&gt;allUsers&lt;/code&gt;)&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read-only mode&lt;/strong&gt; when a client connects without a username&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaFX interfaces&lt;/strong&gt; for both server and client&lt;/li&gt;
&lt;li&gt;Proper &lt;strong&gt;separation between networking logic and UI&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main goal was to combine &lt;strong&gt;network programming with clean application architecture&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Tech Stack&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The system was built using the following technologies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Language:&lt;/strong&gt; Java 17
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Networking:&lt;/strong&gt; Java TCP Sockets
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;UI Framework:&lt;/strong&gt; JavaFX (&lt;code&gt;GridPane&lt;/code&gt; + CSS styling)
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build Tool:&lt;/strong&gt; Maven
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IDE:&lt;/strong&gt; IntelliJ IDEA
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;High-Level Architecture&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The application follows a &lt;strong&gt;Client–Server architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;server&lt;/strong&gt; accepts multiple socket connections.&lt;/li&gt;
&lt;li&gt;Each client connection is handled in a &lt;strong&gt;dedicated thread&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The server &lt;strong&gt;broadcasts incoming messages&lt;/strong&gt; to all connected clients.&lt;/li&gt;
&lt;li&gt;The client UI &lt;strong&gt;displays messages and connection status&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture ensures that the system can support &lt;strong&gt;multiple users simultaneously while maintaining real-time communication&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;MVC / Separation of Concerns&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To keep the application maintainable, we structured both the server and client using a &lt;strong&gt;Model–View–Controller approach&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TCP sockets&lt;/li&gt;
&lt;li&gt;Network input/output&lt;/li&gt;
&lt;li&gt;Chat protocol commands&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;View&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Contains only:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JavaFX UI components&lt;/li&gt;
&lt;li&gt;Layout and CSS styling&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Controller&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Responsible for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Connecting UI events to model logic&lt;/li&gt;
&lt;li&gt;Updating the interface when new messages arrive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Separating networking logic from UI logic made the system &lt;strong&gt;much easier to debug and extend&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Key Features Implemented&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Multi-Client Chat&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The server supports &lt;strong&gt;multiple simultaneous clients&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;All messages are broadcast using the following format:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[HH:mm:ss] username: message
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This timestamped format improves readability during conversations.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;2. Read-Only Mode&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If a user connects &lt;strong&gt;without providing a username&lt;/strong&gt;, the client automatically switches to &lt;strong&gt;READ-ONLY MODE&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user &lt;strong&gt;can receive messages&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;The user &lt;strong&gt;cannot send messages&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows users to observe the chat without actively participating.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;3. &lt;code&gt;allUsers&lt;/code&gt; Command&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When a client sends the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;allUsers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server responds &lt;strong&gt;only to that client&lt;/strong&gt; with the list of active users currently connected to the chat.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;4. Graceful Disconnection&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Clients can close the session cleanly by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bye
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The socket closes correctly&lt;/li&gt;
&lt;li&gt;The user is removed from the server's active list&lt;/li&gt;
&lt;li&gt;The UI updates accordingly&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;5. User-Friendly Status Indicators&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Both server and client applications include UI indicators such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Online / Offline connection status&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;live list of connected users&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Random color highlighting&lt;/strong&gt; for users on the server dashboard&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These features improve usability and monitoring.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Configuration&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Server network parameters are externalized using a configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allows parameters such as &lt;strong&gt;host and port&lt;/strong&gt; to be modified &lt;strong&gt;without recompiling the application&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Build and Run&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Both server and client are packaged as &lt;strong&gt;separate Maven projects&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Server&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;TCPServer
mvn clean package
java &lt;span class="nt"&gt;-jar&lt;/span&gt; target/tcpserver-1.0.0.jar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Client&lt;/strong&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;TCPClient
mvn clean package
java &lt;span class="nt"&gt;-jar&lt;/span&gt; target/tcpclient-1.0.0.jar localhost 3000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Challenges We Faced&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Concurrency and Connection Lifecycle&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Handling multiple client connections while maintaining stable communication required careful management of &lt;strong&gt;thread lifecycle and connection states&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Model–View Decoupling&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Directly updating the JavaFX UI from networking threads can lead to unstable behavior.&lt;/p&gt;

&lt;p&gt;To solve this, we used &lt;strong&gt;callback interfaces and controllers&lt;/strong&gt; to route updates safely to the UI layer.&lt;/p&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;Packaging JavaFX Applications&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;When packaging JavaFX with shaded JARs, &lt;strong&gt;module overlap warnings&lt;/strong&gt; may appear.&lt;br&gt;&lt;br&gt;
These warnings are common in JavaFX builds and typically do not affect runtime behavior.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;What We Learned&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This project provided valuable experience with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Real-world socket programming&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Managing &lt;strong&gt;multiple concurrent clients&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Designing applications with &lt;strong&gt;MVC architecture&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Keeping &lt;strong&gt;network logic independent from UI&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One key takeaway is that &lt;strong&gt;clean architecture significantly simplifies debugging and future improvements&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Future Improvements&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Potential improvements for the project include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Private messaging commands&lt;/strong&gt; (&lt;code&gt;/msg username message&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Persistent chat history&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Migrating to &lt;strong&gt;non-blocking NIO sockets&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Adding &lt;strong&gt;automated integration tests&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Final Thoughts&lt;/em&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Building a chat system is one of the best ways to learn &lt;strong&gt;network programming and concurrency&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This project combined:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Networking&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Desktop UI development&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Concurrency&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Software architecture&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For developers learning Java networking, implementing a &lt;strong&gt;multi-client chat application&lt;/strong&gt; is an excellent hands-on exercise that builds strong practical skills.&lt;/p&gt;

</description>
      <category>java</category>
      <category>networking</category>
      <category>tutorial</category>
      <category>ui</category>
    </item>
  </channel>
</rss>
