Skip to content

Felix-Brodmann/FBNetwork

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FBNetwork

FBNetwork is a C++ network library that provides simple TCP client and server implementations with event queue integration. It is ideal as a foundation for your own network-based applications or to extend existing projects with network functionality.


πŸš€ Features

  • Simple TCP client and server classes
  • Event-driven communication via EventQueue
  • Modular architecture
  • Extendable with optional MySQL integration

πŸ“ Project Structure

FBNetwork/
β”œβ”€β”€ include/
β”‚   β”œβ”€β”€ client.h           # TCP Client Class
β”‚   β”œβ”€β”€ server.h           # TCP Server Class
β”‚   β”œβ”€β”€ eventQueue.h       # Event Management
β”‚   β”œβ”€β”€ extendedSystem.h   # Platform-dependent extensions
β”‚   └── mySQL.h            # (Optional) MySQL Database Integration
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ client.cpp
β”‚   β”œβ”€β”€ server.cpp
β”‚   β”œβ”€β”€ eventQueue.cpp
β”‚   β”œβ”€β”€ extendedSystem.cpp
β”‚   └── mySQL.cpp

πŸ› οΈ Installation

git clone https://github.com/Felix-Brodmann/FBNetwork.git
cd FBNetwork
mkdir build && cd build
cmake ..
make

Note: For MySQL functionality, libmysqlclient is required.


πŸ“š Example: TCP Server

#include "server.hpp"

int main() {
    try
    {
        FBNetwork::Server server(Domain::IPV4_DOMAIN, 12345, 20);  // IPv4, Port 12345 and max 20 connections
        server.startServer();  // Start the server
        server.startListening();  // Start listening for incoming connections
        int clientID = server.acceptClient();  // Accept a client connection in a blocking manner
        std::cout << "Client connected with ID: " << clientID << " and IP: " << server.getClientIpAddress(clientID) << std::endl;
        server.readTillXData(clientID, "\r\n");  // Read data until a specific delimiter
        std::cout << "Received data from client: " << server.getData(clientID) << std::endl;
        server.sendData(clientID, "Hello from server!");  // Send data to the client
        server.closeClient(clientID);  // Close the client connection
        server.stopServer();  // Stop the server
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
    return 0;
}

πŸ™Œ Contribute

Pull requests and suggestions for improvement are always welcome!


πŸ“„ License

FBNetwork Β© 2025 by Felix Brodmann is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages