Skip to content

Lightweight RFC 6455 WebSocket server implementation in C++ from scratch

Notifications You must be signed in to change notification settings

DarkPimbaa/WebSocketCPP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebSocket C++ Server

A lightweight WebSocket server implementation in C++, built from scratch following RFC 6455. No external WebSocket dependencies - just raw socket programming with OpenSSL.

Features

  • RFC 6455 compliant WebSocket protocol implementation
  • WebSocket handshake with SHA-1 and Base64
  • Frame parsing with masking/unmasking
  • Multi-threaded client handling
  • Available as both static and dynamic library
  • Browser-based test client included

Requirements

  • C++17
  • CMake 3.10+
  • OpenSSL

Building

mkdir build && cd build
cmake ..
make

Usage

CMake Integration

find_package(OpenSSL REQUIRED)
find_library(WEBSOCKET_LIB websocket)

add_executable(your_app main.cpp)
target_link_libraries(your_app
    PRIVATE
    ${WEBSOCKET_LIB}
    OpenSSL::SSL
    OpenSSL::Crypto
    pthread
)

Basic Example

#include <websocket.hpp>

int main() {
    WebSocket server(8080);
    server.onMessage([](const std::string& msg) {
        std::cout << "Received: " << msg << std::endl;
    });
    server.start();
    return 0;
}

Project Structure

websocket.hpp   - WebSocket class definition
websocket.cpp   - Protocol implementation (handshake, framing, masking)
main.cpp        - Example server
index.html      - Browser test client
CMakeLists.txt  - Build configuration

License

MIT

About

Lightweight RFC 6455 WebSocket server implementation in C++ from scratch

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published