Skip to content
/ knot Public
forked from r-lyeh-archived/knot

Knot is a lightweight and simple TCP networking C++ library with no dependencies.

Notifications You must be signed in to change notification settings

gasparfm/knot

 
 

Repository files navigation

knot

  • Knot is a lightweight and simple TCP network C++11 library with no dependencies.
  • Knot is tiny. One header and one source file.
  • Knot is cross-platform. Compiles under MSVC/GCC. Works on Windows/Linux.
  • Knot is MIT licensed.

public API

  • knot::connect() connects to a network address.
  • knot::send() sends data bytes thru a connection.
  • knot::receive() receives data bytes from a connection.
  • knot::receive() receives data bytes from a http connection.
  • knot::disconnect() closes an established connection.
  • knot::listen() creates a listening thread.
  • knot::shutdown() shutdowns a listening thread.
  • knot::sleep() puts a thread to sleep.
  • knot::reset_counters() reset transmission stats.
  • knot::get_bytes_received() get number of bytes received since last reset.
  • knot::get_bytes_sent() get number of bytes received since last reset.
  • knot::get_interface_address() get address of current interface address (requires an established connection)
  • knot::lookup() get uri from url or host:port address.
  • knot::close_r() disable read operations on socket.
  • knot::close_w() disable write operations on socket.

sample

#include <iostream>
#include "knot.hpp"

int main( int argc, const char **argv )
{
    int socket;
    std::string answer;
    std::cout << "answer from NTP server: ";

    if( knot::connect( socket, "time-C.timefreq.bldrdoc.gov", "13" ) )
        if( knot::send( socket, "dummy" ) )
            if( knot::receive( socket, answer ) )
                std::cout << answer << std::endl;

    knot::disconnect( socket );

    return 0;
}

possible output

D:\prj\knot>cl sample.client.ntp.cc knot.cpp
D:\prj\knot>sample.client.ntp.exe
answer from NTP server:
56400 13-04-18 13:34:19 50 0 0  52.0 UTC(NIST) *
D:\prj\knot>

special notes

  • g++ users: both -std=c++11 and -lpthread may be required when compiling knot.cpp
  • clang++ users: both -std=c++11 and -stdlib=libc++ may be required.

About

Knot is a lightweight and simple TCP networking C++ library with no dependencies.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.6%
  • Emacs Lisp 3.4%