patrickjwhite / lnetlib

C++ network library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

lnetlib: C++ network library

lnetlib (or lightweight network library) is a small C++ network library with simple API for quick development network applications. This library is based on non-Boost Asio and has written on modern C++11.

lnetlib has next features:

  • multithreading server
  • stream abstraction over network
  • request/response model
  • optional encryption

Internal dependencies

  • Asio
  • lsignal

Introduction

Directory Description
lnetlib/ Core files of library
lnetlib/asio/ Network subsystem
lnetlib/lsignal/ Signal/slot subsystem
example/ Example of using lnetlib
example/client/ Client application
example/server/ Server application

How to use

Just copy lnetlib directory in your project or create standalone static/dynamic library from it.

Library divided into two core classes - server and client. First of all, create instance of client or server class and connect your defined slots to necessary signals. If you want to use encryption you should init encryption options before client or server will be started. Also, you can setup desired thread policy (for server only). Finally, start listening (for server) or connect to server (for client).

Essential classes

connection

This class handle active connection between client and server. Although signals of this class routing through client/server class you can directly connect to them:

Signal Description
closed Emit if connection is closed
error Emit if error is raised
received Emit if input data available

Method create_stream creates output network stream for target command and can accept response callback which will be called if you create response of this stream/command on the other peer.

ostream

Subclass of std::ostream. This is representation of output network stream. Method send sends data.

istream

Subclass of std::istream. This is representation of input network stream. Method create_response creates response output stream (see description of connection class).

encryption

Through this class you can set necessary encryption options:

Option Description
encryption method Enable appropriate SSL protocol (SSLv2, SSLv2, etc)
CA Set certificate authority
certificate Set PEM certificate
private key Set PEM private key
verify mode Enable peer verify mode (see ssl_verify_mode)
verify callback Set callback for verificaton peer certificate
server

Server supports two thread policies:

Thread policy Description
one_per_connection Every new connection creates new thread
fixed_count Fixed thread count

Although lnetlib uses only one i/o service, which is shared between server threads, all network operations are asynchonous.

This class contains such signals:

Signal Description
connected Emit if new connection is established
disconnected Emit if connection is closed
error Emit if error is raised
received Emit if input data available
client

This class contains such signals:

Signal Description
refused Emit if server refused connection
connected Emit if connection is established
disconnected Emit if connection is closed
error Emit if error is raised
received Emit if input data available

Example

This console application illustrates features of library lnetlib.

About

C++ network library

License:MIT License


Languages

Language:C++ 99.1%Language:QMake 0.9%Language:C 0.0%