A simple client-server chat application built with Winsock2 & Win32 API. This project demonstrates low-level network programming and custom GUI framework development, helping to understand how libraries like wxWidgets and Qt work under the hood.
- Client-server architecture with TCP sockets
- Custom event-driven GUI framework ("Engine")
- Layer-based application architecture
- Template-based protocol serialization
- Multi-threaded server supporting multiple concurrent clients
- Custom widget system (Panel, Button, TextInput)
- Requirements
- Dependencies
- Project Structure
- Installation
- Building
- Usage
- Architecture
- Testing
- Known Limitations
- License
- C++17 compiler (MSVC recommended)
- Windows OS
- CMake 3.10+
- Google Test (included as submodule)
- Winsock2 (ws2_32.lib)
- Win32 API
chat-app/
├── app/ # Main application
│ ├── src/ # Chat app implementation
│ └── include/app/ # Chat app headers
├── engine/ # Custom GUI framework
│ ├── include/engine/ # Engine headers (Window, Panel, Events, Layers)
│ └── src/ # Engine implementations
├── network_core/ # Networking library
│ ├── include/ # Network headers (Socket, Connection, Protocol)
│ ├── src/ # Network implementations
│ └── test/ # Network unit tests
└── lib/ # Third-party libraries
└── googletest/ # Google Test framework
Clone the repository with submodules:
git clone https://github.com/benofthebens/chat-app.git --recurse-submodules
cd chat-appIf you already cloned without submodules:
git submodule update --init --recursive# Configure
cmake --preset x64-debug
# Build
cmake --build out/build/x64-debugFor release builds:
cmake --preset x64-release
cmake --build out/build/x64-release# Configure
cmake --preset mingw-debug
# Build
cmake --build out/build/mingw-debugThe project builds two executables:
The main GUI client application with integrated networking.
./out/build/x64-debug/app/App.exe- Type messages in the text input box
- Click the button to send messages
- Messages from other clients appear in message boxes
A dedicated server for hosting chat sessions.
./out/build/x64-debug/app/Server.exeThe server listens on 127.0.0.1:8080 and broadcasts messages to all connected clients.
- Start the server:
./out/build/x64-debug/app/Server.exe- Launch one or more client instances:
./out/build/x64-debug/app/App.exe- Clients automatically connect to
127.0.0.1:8080on startup
A custom event-driven GUI framework built on Win32 API:
- Application: Main application loop and layer management
- Window: Top-level window with event callbacks
- Panel: Base widget class supporting hierarchical UI
- Layer: Application state/screen abstraction
- Event System: Type-safe event dispatching (Window, Custom events)
- GraphicsContext: Rendering abstraction over Win32 GDI
Widgets:
Button: Clickable button with callback supportTextInput: Single-line text input field
Generic networking library with template-based protocol handling:
- Socket: Low-level Winsock2 wrapper
- Connection: Server and Client connection abstractions
- ProtocolHandler: Template-based serialization/deserialization
- Session: Manages individual client sessions
- ApplicationServer/Client: High-level server and client implementations
Combines Engine and NetworkCore using a layered architecture:
- ChatAppLayer: Handles UI rendering and chat events
- NetworkLayer: Manages network communication in separate thread
- Custom Events:
MessageSendEvent,MessageReceiveEvent
Run the network core tests:
# Using CTest
ctest --test-dir out/build/x64-debug/network_core/test
# Or run directly
./out/build/x64-debug/network_core/test/NetworkCoreTests.exe- Hardcoded server address (127.0.0.1:8080)
- No encryption or authentication
- Windows-only (uses Win32 API)
- Basic error handling
- Fixed message size (1024 bytes)
- Configurable server IP/port
- Chat history view with scrollable message list
- User nicknames and avatars
- Persistent message storage
- Reconnection logic
- Cross-platform support (abstract GUI layer)
- Better visual design and UX
- Private messaging
Apache License 2.0 - See LICENSE.txt for details.
This project was built to understand:
- How GUI frameworks abstract Win32 API
- Network programming with Winsock2
- Event-driven architectures
- Layer-based application design
- Template metaprogramming for protocols