Skip to content

About

A simple object oriented networking server in C++ utilizing Bazel build tool

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

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!

About

A simple object oriented networking server in C++ utilizing Bazel build tool

Resources

Stars

1 star

Watchers

1 watching

Forks

Contributors

Languages