Skip to content
forked from ruoka/net4cpp

Network library implemented with C++20 standard

License

Notifications You must be signed in to change notification settings

aseyado/net4cpp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

net4cpp

Network library based on C++20 standard

Echo Server Example

try
{
    auto ator = acceptor{"::1", "2112"}; // IPv6 localhost
    auto s = ator.accept();

    while(s)
    {
        auto echo = ""s;
        getline(s, echo);
        s << echo << endl;
        clog << echo << endl;
    }
}
catch(const exception& e)
{
    cerr << "Exception: " << e.what() << endl;
}

Http Request Example

try
{
    auto s = connect("http://www.google.com");

    s << "GET / HTTP/1.1"                << crlf
      << "Host: www.google.com"          << crlf
      << "Connection: close"             << crlf
      << "Accept: text/plain, text/html" << crlf
      << "Accept-Charset: utf-8"         << crlf
      << crlf
      << flush;

    while(s)
    {
        auto c = ' ';
        s >> noskipws >> c;
        clog << c;
    }
    clog << flush;
}
catch(const exception& e)
{
    cerr << "Exception: " << e.what() << endl;
}

Syslog Stream Example

#include "net/syslogstream.hpp"

[...]

slog.level(syslog::severity::info);
slog.facility(syslog::facility::local0);
slog.tag("example");

auto clothes = "shirts"s; auto spouse = "wife"; auto wrong = false;

slog << debug   << "... " << 3 << ' ' << 2 << ' ' << 1 << " Liftoff" << flush;

slog << info    << "The papers want to know whose " << clothes << " you wear..." << flush;

slog << notice  << "Tell my " << spouse << " I love her very much!" << flush;

slog << warning << "Ground Control to Major Tom Your circuit's dead, there's something " << boolalpha << wrong << '?' << flush;

slog << error   << "Planet Earth is blue and there's nothing I can do." << flush;

About

Network library implemented with C++20 standard

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 97.5%
  • Makefile 2.5%