Skip to content

Latest commit

 

History

History
108 lines (73 loc) · 2.98 KB

README.md

File metadata and controls

108 lines (73 loc) · 2.98 KB

Web Server in C++

This project provides a modular C++ networking solution with reusable components for building and testing socket servers.

What's Inside?

  • 🧩 Modular Design: Organized into server and socket components for clarity and scalability.
  • 🔌 Socket Abstraction: Easy-to-use classes for creating binding and listening sockets.
  • 🚀 Test Server: A simple server implementation for quick development and testing.
  • 🛠️ Custom Networking Tools: Extendable components to suit your networking needs.

Directory Structure

.
├── BUILD.bazel
├── MODULE.bazel
├── MODULE.bazel.lock
├── README.md
├── main_server.cpp
├── main_socket.cpp
└── networking
    ├── BUILD.bazel
    ├── lib
    │   ├── BUILD.bazel
    │   ├── binding_socket
    │   │   ├── BUILD.bazel
    │   │   ├── binding_socket.cpp
    │   │   └── binding_socket.hpp
    │   ├── lib.hpp
    │   ├── listening_socket
    │   │   ├── BUILD.bazel
    │   │   ├── listening_socket.cpp
    │   │   └── listening_socket.hpp
    │   └── socket
    │       ├── BUILD.bazel
    │       ├── socket.cpp
    │       └── socket.hpp
    └── server
        ├── BUILD.bazel
        ├── server.cpp
        ├── server.hpp
        ├── test_server.cpp
        └── test_server.hpp

Compilation

Using Bazel for compiling and runnig the applications

  • Buidling the main_socket lib bash bazel build //:main_socket
  • Running the main_socket lib bash bazel run //:main_socket
  • Buidling the main_server lib bash bazel build //:main_server
  • Running the main_server lib bash bazel run //:main_socket

If you are willing to build the supporting the libraries

  • Buidling the socket lib bash bazel build //networking/lib/socket:socket
  • Buidling the server lib bash bazel build //networking/server/server:server

Working Explained

Server Initialization: The Server base class initializes sockets and manages communication.

Test Server: The TestServer class extends the Server class and handles:

  • acceptor(): Accepts incoming connections.
  • handler(): Reads client messages.
  • responder(): Sends responses back to the client.

Socket Abstraction:

  • Provides reusable components for binding, listening, and handling sockets.

Screens

The browser making the request and getting the response

browser view

The server logs

browser view

Using G++?

To compile the test server

g++ -std=c++11 -I./networking   main_server.cpp networking/*/*.cpp  -o server

To compile the socket listener

g++ -std=c++11 -I./networking   main_socket.cpp networking/*/*.cpp  -o socket

Credits

Thanks to Eric's Videos which made this possible!