Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ershehzan/SecureWebSocketClient-Cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

158 Commits

Repository files navigation

πŸš€ SecureWebSocketClient-Cpp

A Native C++17 Secure WebSocket Client (Winsock + OpenSSL)

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.


⭐ Why This Project Stands Out

πŸ”Ή Fully Native WebSocket Stack

Implements the protocol manually:

  • HTTP Upgrade β†’ 101 Switching Protocols
  • Base64 nonce generation
  • Frame masking/unmasking
  • Bit-level frame construction
  • Opcode handling

πŸ”Ή Secure by Design

Uses OpenSSL for TLS handshaking and encrypted communication.

πŸ”Ή Windows-Native

Built using:

  • Winsock2
  • CMake
  • MSVC (Visual Studio)
  • vcpkg for dependency management

πŸ”Ή Clean, Modular Codebase

Separated into:

  • websocket_client.*
  • tls_context.*
  • cli.*
  • tests/

🧩 Features

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

πŸ› οΈ Tech Stack

  • C++17
  • Windows API (Winsock2)
  • OpenSSL (via vcpkg)
  • CMake Build System
  • MSVC Toolchain

πŸ“¦ Installation & Build Guide

1️⃣ Install Dependencies

vcpkg install openssl:x64-windows

2️⃣ Configure the Project

mkdir build
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=C:/Users/ershe/vcpkg/scripts/buildsystems/vcpkg.cmake -A x64

3️⃣ Build

cmake --build build --config Release

4️⃣ Run

./build/Release/websocket_client.exe

🧠 Core Concepts Learned

πŸ”Έ WebSocket Protocol (RFC 6455)

  • HTTP Upgrade handshake
  • Sec-WebSocket-Key + Base64
  • Accept hash using SHA-1
  • Opcode handling

πŸ”Έ Secure Networking

  • TLS handshake
  • Certificate validation
  • OpenSSL BIO socket integration

πŸ”Έ Windows Systems Programming

  • Winsock socket creation
  • Address resolution
  • TCP stream communication

πŸ”Έ Low-Level Bit Manipulation

  • ASN.1 compliant masking
  • Payload segmentation
  • Frame packing/unpacking

πŸ§ͺ Testing

Inside tests/:

  • Automated connect / send / receive test
  • Asserts handshake success
  • Tests echo server consistency

Run manually:

./build/Release/websocket_tests.exe

πŸ“ Project Structure

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

πŸ“œ License

This project is licensed under the MIT License.


✨ Created By

Shehzan Khan

About

A robust, asynchronous WebSocket client built from scratch using C++17, Winsock, and OpenSSL. Implements the RFC 6455 handshake, bitwise frame masking, and secure WSS communication without external WebSocket libraries.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /