- 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 zlib/libpng licensed.
namespace knot {
connect(); // connects to a network address.
send(); // sends data bytes thru a connection.
receive(); // receives data bytes from a connection.
receive(); // receives data bytes from a http connection.
disconnect(); // closes an established connection.
listen(); // creates a listening thread.
shutdown(); // shutdowns a listening thread.
sleep(); // puts a thread to sleep.
reset_counters(); // reset transmission stats.
get_bytes_received(); // get number of bytes received since last reset.
get_bytes_sent(); // get number of bytes received since last reset.
get_interface_address(); // get address of current interface address (requires an established connection)
lookup(); // get uri from url or host:port address.
close_r(); // disable read operations on socket.
close_w(); // disable write operations on socket.
}
#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;
}
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>
- g++ users: both
-std=c++11
and-lpthread
may be required when compilingknot.cpp
- clang++ users: both
-std=c++11
and-stdlib=libc++
may be required.
- v1.0.0 (2015/09/10)
- Initial semantic versioning adherence