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 x64cmake --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.exeSecureWebSocketClient-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