Skip to content

C++ command-line WebSocket client application that connects to public echo servers, sends and receives messages, and supports secure WebSocket (wss) connections. It is built using the GN (Generate Ninja) build system, includes unit tests, and supports both GCC and Clang compilers.

Notifications You must be signed in to change notification settings

riddhi-testcases/Cpp-Websocket-Client

Repository files navigation

C++ WebSocket Client with GN Build System

This project is a C++ command-line WebSocket client application that connects to public echo servers, sends and receives messages, and supports secure WebSocket (wss) connections. It is built using the GN (Generate Ninja) build system, includes unit tests, and supports both GCC and Clang compilers.

Features

  • Connects to public WebSocket echo servers
  • Send and receive text messages
  • Command-line interface for interaction
  • Graceful handling of connection errors and disconnections
  • SSL/TLS support for secure WebSocket connections
  • GN build system with separate debug and release targets
  • Unit tests for critical components
  • Compatible with both GCC and Clang compilers

Prerequisites

  • C++17 compatible compiler (GCC or Clang)
  • Python (for GN generation)
  • Ninja build system
  • OpenSSL (for wss support)

Setting Up GN

  1. Clone and build GN:

    git clone https://gn.googlesource.com/gn
    cd gn
    python build/gen.py
    ninja -C out
    
  2. Add the GN binary to your system PATH

Building the Project

  1. Generate build files with GN
  2. Build using Ninja

Running the Application

Navigate to the output directory and run the compiled binary.

The program will prompt you to enter messages to send and display messages received from the echo server.

Unit Testing

Unit tests are located in the test/ directory.

Tests cover:

  • Successful connection and disconnection
  • Message send and receive operations
  • Error scenarios

SSL/TLS Support

This project supports secure WebSocket connections (wss) using OpenSSL. Make sure OpenSSL is installed and properly linked during compilation. You can use pkg-config or manually configure GN args to link OpenSSL libraries.

Supported Echo Servers

Bonus Features Implemented

  • Secure WebSocket (wss://) with OpenSSL
  • Compatible with both GCC and Clang compilers
  • Modular code with separation of concerns
  • Unit test suite for core components

References

About

C++ command-line WebSocket client application that connects to public echo servers, sends and receives messages, and supports secure WebSocket (wss) connections. It is built using the GN (Generate Ninja) build system, includes unit tests, and supports both GCC and Clang compilers.

Topics

Resources

Stars

Watchers

Forks