A lightweight, high-performance WebSocket client built from scratch, implementing the full WebSocket RFC 6455 handshake, framing logic, masking, and TLS encryption β without using any external WebSocket libraries.
This client connects to secure WSS servers, performs the HTTP Upgrade handshake, encrypts packets using OpenSSL, and handles full-duplex messaging.
Implements the protocol manually:
- HTTP Upgrade β
101 Switching Protocols - Base64 nonce generation
- Frame masking/unmasking
- Bit-level frame construction
- Opcode handling
Uses OpenSSL for TLS handshaking and encrypted communication.
Built using:
- Winsock2
- CMake
- MSVC (Visual Studio)
- vcpkg for dependency management
Separated into:
websocket_client.*tls_context.*cli.*tests/
| Feature | Description |
|---|---|
| βοΈ Secure WSS support | Encrypted WebSocket over TLS |
| βοΈ Manual frame construction | FIN, Opcode, Payload Length, Masking |
| βοΈ True full-duplex | Separate listening + sending threads |
| βοΈ Native sockets | No Boost or external WebSocket libs |
| βοΈ Unit tests | Simple connection and echo tests |
| βοΈ Clean CLI | /exit, message input, and error reporting |
- C++17
- Windows API (Winsock2)
- OpenSSL (via vcpkg)
- CMake Build System
- MSVC Toolchain
vcpkg install openssl:x64-windowsmkdir build cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:/Users/ershe/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64
cmake --build build --config Release
./build/Release/websocket_client.exe
- HTTP Upgrade handshake
Sec-WebSocket-Key+ Base64- Accept hash using SHA-1
- Opcode handling
- TLS handshake
- Certificate validation
- OpenSSL BIO socket integration
- Winsock socket creation
- Address resolution
- TCP stream communication
- ASN.1 compliant masking
- Payload segmentation
- Frame packing/unpacking
Inside tests/:
- Automated connect / send / receive test
- Asserts handshake success
- Tests echo server consistency
Run manually:
./build/Release/websocket_tests.exe
SecureWebSocketClient-Cpp
β CMakeLists.txt
β LICENSE
β
βββ src
β βββ main.cpp
β βββ cli/
β β cli.h
β β cli.cpp
β βββ websocket/
β websocket_client.h
β websocket_client.cpp
β tls_context.h
β tls_context.cpp
β
βββ tests/
websocket_client_test.cpp
This project is licensed under the MIT License.
Shehzan Khan