How ohad-shai/chat-app works
Project type and purpose
• This is a classic client-server chat application written in C# using WinForms.
• It consists of two interactive frontends (Client GUI and Server GUI), two logic layers (Client Logic and Server Logic), and a shared Communicator library handling message serialization and TCP transport.
File structure
• Top level: OhadsChat.sln, README.md, plus four subprojects and one shared library.
• “Client GUI” and “Server GUI” hold WinForms code, dialogs, resources, and references to their respective “Logic” projects.
• “Client Logic” and “Server Logic” contain core business logic (user management, message dispatching, threading).
• “Communicator” is a reusable class library defining ChatMessage, MessageType, and a Communicator component wrapping TcpClient/TcpListener, streams, serialization, and events.
• Each GUI project depends on its Logic project, which in turn depends on Communicator.
Key insights from README.md
• Focus areas: Delegates & Events, TCP (TcpClient/TcpListener), Serialization, Threading, WinForms.
Main components
a. Client GUI (WinForms)
b. Client Logic (business rules, threading, login state, chat room management)
c. Communicator library (message framing, serialization, network I/O, events)
d. Network (TCP connection over IP)
e. Server Logic (connection listener, per-client handlers, message routing)
f. Server GUI (administration console, chat room monitoring)
Relationships and data flow
• The Client GUI issues login/send-message requests to Client Logic.
• Client Logic packages ChatMessage objects and calls Communicator.Connect/Send.
• Communicator serializes ChatMessage → writes to TCP stream → network.
• On server side, Communicator.Accept/Receive parses incoming data into ChatMessage and raises events to Server Logic.
• Server Logic dispatches messages to all or specific clients by calling Communicator.Send back to client sockets.
• Server GUI subscribes to Server Logic events (new connection, new message) for display and control.
Architectural patterns and design principles
• Layered architecture: UI layer → Logic layer → Communication layer → Network.
• Event-driven callbacks: Communicator exposes events (MessageReceived, ClientConnected).
• Separation of concerns: UI is dumb; all TCP and threading are encapsulated in Communicator and Logic.
• Reusable library (Communicator) shared by both client and server.