Giter Site home page Giter Site logo

sednl's Introduction

SedNL

Simple Event Driven Network Library

Version 1.0 is now in Beta!

A network library

SedNL is a C++11 network library with a high level API. It is event driven, which means you bind functions on events and your callback will be asynchronously called in a multi-threaded environment. This reduce network to 'designing good events' and 'reacting to events'.

SedNL use TCP to send and receive events.

Binary release (Version 1.0)

Linux

32 Bits beta release is available here. 64 Bits beta release is available here.

Installation

Linux

Installation is simple. First, you have to git clone https://github.com/Zenol/sednl.git. Then, create a build directory. We will use a build directory in the clone : cd sednl ; mkdir build. And now, we generate all the makefiles with cmake ... Then, you are home, and you can type make ; sudo make install.

Windows

You should use cmake.exe / cmake-gui.exe. If you want to build in sednl/build, to generate MinGW makefiles you can type cmake -G "MinGW Makefiles" ...

Notice that Visual Studio's compiler isn't C++11 compliant, and it's probably that SedNL won't build. Seams like VC++ 2013 will solve it. You can use Visual Studio with Clang++ or MinGW (or any C++11 compiler).

Binding on events

Binding on events is really easy. Here is a small sample :

// Your callbacks :
void my_on_connect(Connection& c);
void my_on_disconnect(Connection& c);
void my_hello_msg(Connection& c, const Event& e);
void my_say_something(Connection& c, const Event& e);
void my_apples(Connection& c, const Event& e);


// Create a server
TCPServer server(SocketAddress(7777));

// Bind my_on_connect and listen from server
EventListener listener(server);
listener.on_connect().set_function(my_on_connect);

// Bind some events
EventConsumer consumer(listener);
consumer.on_disconnect(my_on_disconnect);
consumer.bind("hello_msg").set_function(my_hello_msg);
consumer.bind("say_something").set_function(my_say_something);
consumer.bind("apples").set_function(my_apples);

// Launch listener thread and consumer thread
listener.run();
consumer.run();

// Do what you want in the main thread ...

// Stop listener, close connections, and wait for the end of event processing.
listener.join();
consumer.join();

API documentation

You can look at examples to have simple examples of use.

Documentation (very detailed) is available here : http://zenol.fr/sednl/

Design

SedNL use queue to store events when they are received. That's the job of the EventListener class. Then, queues are read by consumers thread. Creating a thread and setting callbacks is the work of the EventConsumer class.

For easy building of message, we provide a serialisation macro (although you can write yourself the small template code generated) and rely on variadic templates. Events are instances of the Event class, which is nothing more than a Packet instance with a name. The packet class provide way to stack data and build an Event.

For short events, it's easier to write the packet by hand. For more complex object, the good choice is serialising big objects so that your packet reduce to few serialized object. This way, your code is more flexible.

You may notice that most of the library code isn't networking, but providing a hight level API so that you don't have to worry (too much) about concurency, and hide the complexity of using condition variables, mutexes, etc.

Build Status

sednl's People

Contributors

jeremycochoy avatar

Watchers

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.