How torchman005/simple-chat-room works
Project type and purpose
• This is a classic client-server, socket-based chat application written in Java SE.
• It consists of two Maven modules:
• ChatServer – the server that accepts socket connections, manages client threads, routes messages.
• ChatClient – the desktop client (JavaFX UI) that connects to the server, sends/receives messages and files.
• A shared domain module (chatcommon) holds the Message, User, MessageType, UserType classes used by both.
High-level architecture analysis
• Top-level modules:
• chatcommon (shared DTOs)
• chatserver (server application)
• chatclient (client application)
• Key patterns:
• MVC-style layering in the client (UI ↔ service ↔ networking)
• Multi-threaded server: one thread per client, managed by a thread manager
• Simple in-memory data structures for groups and online-user lists (no persistence layer)
Main components
A. Client side
1. UI Layer (JavaFX):
– LoginUI, ChatUI, PrivateChatDialog, GroupChatDialog, FileSendDialog, etc.
2. Service Layer:
– ClientMessageService (package: service)
– FileClientService, ToUserFunction, Group utility
– ClientConnServerThreadsManage – coordinates client networking threads
3. Networking Layer:
– ClientConnectServerThread – maintains socket I/O with ChatServer
4. Resources:
– config.properties (server IP, port)
– styles.css, images for JavaFX theming
B. Shared Domain (chatcommon)
– Message, MessageType
– User, UserType
• These classes define the payload and metadata exchanged over sockets
C. Server side
1. Entry Point:
– ChatServer main class (socket listener on port 2323)
2. Thread Management:
– ServerConnectClientThread – one per connected client
– ClientThreadsManage – registry of live client threads
3. Business Logic:
– Groups – manages group-chat memberships
– OnlineUsers – tracks logged-in users
– SendNewsToAllService – broadcasts system messages
4. Admin UI:
– ChatFrame – simple JavaFX window showing server events/logs
5. Optional persistence (configured via JDBC if enabled)
Relationships and data flows
• Client UI → Service Layer → ClientConnectServerThread → Socket → Server’s ChatServer listener
• ServerChatServer accepts connection → spawns ServerConnectClientThread → registers with ClientThreadsManage
• Incoming Message DTOs flow:
• ServerConnectClientThread → dispatch logic → appropriate thread(s) → back to ClientConnectServerThread → socket out → ClientReceive
• File transfers piggyback on the same socket channel with file-specific MessageType
• Shared DTOs travel over the wire (no separate REST/API layer)
Architectural patterns & principles
• Layered architecture (presentation → business/service → networking)
• Single-responsibility classes (each service class handles one function)
• Thread-per-connection model on server
• Use of configuration file for decoupling environment settings
• Shared domain module prevents duplication
Technologies & frameworks
• JavaSE 17
• Java Sockets (java.net.Socket/ServerSocket)
• JavaFX for desktop UI
• Maven for build & dependency management
• JUnit for unit tests
• (Optional) JDBC/MySQL if persistence is added
• Arrowheads for data-flow direction
• Configuration externalized (config.properties)
• Call out JavaFX, Sockets, Maven