Giter Site home page Giter Site logo

anonymous-275 / netlibpp Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 11 KB

netlibpp is a modern cross-platform C++ network library that supports TCP/UDP protocols, and compatible with C++11, C++14, C++17, and C++20.

License: MIT License

CMake 9.86% C++ 90.14%
c-plus-plus cpp cpp11 cpp14 cpp17 header-only header-only-library library network network-library

netlibpp's Introduction

netlibpp

CMake Linux Build CMake Windows Build

netlibpp is a modern header only cross-platform C++ network library for developing network services using TCP/UDP protocols, it supports C++11, C++14, C++17, and C++20.

TCP client example:

#include "netlibpp.h"
#include <iostream>
int main() {
    netlibpp::Client Client([](const std::string& error) {
        std::cout << "Error: " << error;
    }, netlibpp::TCP);

    if(Client.has_error())return 1;

    Client.set_target("127.0.0.1", 2030);
    Client.connect();

    while(Client.connected()) {
        Client.send("hello\n");
        auto message = Client.receive(8);
        if(!message.empty()) {
            std::cout << message.data() << " : " << message.size() << "\n";
        }
    }

    return 0;
}

UDP client example:

#include "netlibpp.h"
#include <iostream>

int main() {
    netlibpp::Client Client([](const std::string& error) {
        std::cout << "Error: " << error;
    }, netlibpp::UDP);

    if(Client.has_error())return 1;

    Client.set_target("127.0.0.1", 2031);
    netlibpp::messageType message;

    do {
        Client.send("hello\n");
        message = Client.receive(8);
        if (!message.empty()) {
            std::cout << message.data() << " : " << message.size() << "\n";
        }
    } while(!Client.has_error() && !message.empty());

    return 0;
}

netlibpp's People

Contributors

anonymous-275 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.