Git Product home page Git Product logo

knot's Introduction

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 zlib/libpng licensed.

Public API

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.
}

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.

Changelog

  • v1.0.0 (2015/09/10)
    • Initial semantic versioning adherence

knot's People

Contributors

gasparfm avatar r-lyeh avatar

Watchers

AbdAllah Aly avatar James Cloos 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.