Giter VIP home page Giter VIP logo

libjaypea's Introduction

Jay got pea.

libjaypea

A C++11 networking library with examples.

Limited to "Linux" environments. Scripts are tested and used on CentOS 7.

Uses:

  • Lots of C.
  • CryptoPP for symmetric key encryption.
  • OpenSSL for private key encryption.
  • libpqxx for PostgreSQL integration.
  • DigitalOcean API for quick deployments.

Implementation Example

  • Execute some commands to load and build the library:
git clone https://github.com/bwackwat/libjaypea
cd libjaypea
bin/setup-centos7.sh
bin/build-library.sh
  • Implement the library e.g. a simple echo server (echo.cpp):
#include "tcp-server.hpp"

int main(int, char**){
	EpollServer server(10000, 10);

	server.on_read = [&](int fd, const char* packet, size_t length)->ssize_t{
		if(server.send(fd, packet, length)){
			return -1;
		}
		return length;
	};

	server.run();

	return 0;
}
  • Build your code:
bin/build-with-library.sh
> Usage: <relative path to cpp file> <executable name> <optional additional libraries/compiler flags>
bin/build-with-library.sh echo.cpp echo
  • Run your code:
build/echo

Example Explanation

The example above creates a multithreaded tcp epoll server listening on port 10000, with a maximum of 10 open sockets per thread.

It is a basic echo server.

server.on_read is the definitive function that will be called every time a fd (socket connection) has provided data to read.

server.send will return true on error. If it fails, the lambda returns -1; this will close the connection for safety purposes.

If the send succeeds, then the function returns with a success code (the given length).

server.run will start the server with a number of threads usually equal to the number of available hyperthreads (std::thread::hardware_concurrency()).

Provided Examples

In order of coolness.

  1. bwackwat. Hopefully this example will replace NGINX running on bwackwat.com...
  2. comd/com. An AES encrypted server and client. The server provides access to a shell, the client sends commands to that remote shell. Like sshd/ssh.
  3. message-api. An HTTPS JSON API.
  4. pgsql-provider. A secure database abstraction layer using pgsql-model as an ORM.
  5. pgsql-model-test. A simple class to query a PostgreSQL database in a common way.
  6. ponal-server/ponal-client. A simple redis-inspired key-value store server and corresponding client.
  7. tcp-poll-server. A TCP server able to manage many connections using poll.
  8. tcp-client. You can speed test an TCP server.
  9. echo-server. A fast, simple echo server.
  10. chat-server/chat-client. An incomplete chat server and client.
  11. read-stdin-tty. A tool to read from STDIN tty in raw mode.
  12. keyfile-gen. Creates a key for comd/com.
  13. http-redirecter. Redirects HTTP traffic. Good practice.
  14. json-test. Tests JSON parsing.
  15. queue-test. Tests the queue implementation.

libjaypea's People

Contributors

bwackwat avatar

Watchers

James Cloos avatar Slava Maslennikov avatar  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.