GithubHelp home page GithubHelp logo

threeal / simple-web Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 77 KB

A simple HTTP, HTTPS, WS and WSS server and client library

License: MIT License

CMake 1.70% C++ 98.30%
http https websocket http-server http-client http-library websocket-library

simple-web's Introduction

Simple Web

A very simple, fast, multithreaded, platform independent HTTP, HTTPS, WebSocket (WS) and WebSocket Secure (WSS) server and client library implemented using C++11 and Asio (both Boost.Asio and standalone Asio can be used). Created to be an easy way to make REST resources and WebSocket endpoints available from C++ applications.

This project was created from the merge of Simple Web Server (version 3.0.2) and Simple Websocket Server (version 2.0.0) as a single library to simplify the deploying of it on the Debian operating system.

Features

  • Asynchronous request and message handling
  • Thread pool if needed
  • Platform independent
  • HTTP/1.1 supported, including persistent connections
  • HTTPS supported
  • WebSocket Secure support
  • Chunked transfer encoding and server-sent events
  • Can set timeouts for request/response and content
  • Can set max request/response size
  • Sending outgoing messages is thread safe
  • Client creates necessary connections and perform reconnects when needed
  • RFC 6455 mostly supported: text/binary frames, fragmented messages, ping-pong, connection close with status and reason.
  • Timeouts, if any of SocketServer::timeout_request and SocketServer::timeout_idle are >0 (default: SocketServer::timeout_request=5 seconds, and SocketServer::timeout_idle=0 seconds; no timeout on idle connections)
  • Simple way to add WebSocket endpoints using regex for path, and anonymous functions
  • An easy to use WebSocket and WebSocket Secure client library
  • C++ bindings to the following OpenSSL methods: Base64, MD5, SHA1, SHA256 and SHA512 (found in crypto.hpp)

Dependencies

  • Boost.Asio or standalone Asio
  • OpenSSL libraries

Updating the Library

  • Clone and checkout both Simple Web Server and Simple Websocket Server to the latest release.
  • Merge both header files (*.hpp) of the library and put it under include/simpleweb directory.

    Note: both library could contains the same header files. Make sure to checkout the repository on version that make both library contains the same header version, else you need to fix the conflict manually.

  • Rename some header files as follow:
    • rename client_http.hpp to http_client.hpp.
    • rename client_https.hpp to https_client.hpp.
    • rename client_ws.hpp to ws_client.hpp.
    • rename client_wss.hpp to wss_client.hpp.
    • rename server_http.hpp to http_server.hpp.
    • rename server_https.hpp to https_server.hpp.
    • rename server_ws.hpp to ws_server.hpp.
    • rename server_wss.hpp to wss_server.hpp.

    Note: don't forget to fix the #include definition and the header guard for each source files and header files to match the new header path. (Example: change from #include "client_http.hpp" to #include "simple_web/http_client.hpp")

  • Put example files including the html examples of both library under examples directory.
  • For every source files and header files in this project, make the following changes:
    • Rename some macro definitions as follow:
      • change USE_STANDALONE_ASIO to SIMPLEWEB_USE_STANDALONE_ASIO.
      • change HAVE_OPENSSL to SIMPLEWEB_USE_STANDALONE_ASIO.
      • change HAVE_OPENSSL to SIMPLEWEB_USE_OPENSSL.
    • Add some namespaces as follow:
      • add SimpleWeb::HttpServer = SimpleWeb::SocketServer<SimpleWeb::HTTP> inside simpleweb/server_http.hpp.
      • add SimpleWeb::HttpClient = SimpleWeb::SocketClient<SimpleWeb::HTTP> inside simpleweb/client_http.hpp.
      • add SimpleWeb::HttpsServer = SimpleWeb::SocketServer<SimpleWeb::HTTPS> inside simpleweb/server_https.hpp.
      • add SimpleWeb::HttpsClient = SimpleWeb::SocketClient<SimpleWeb::HTTPS> inside simpleweb/client_https.hpp.
      • add SimpleWeb::WsServer = SimpleWeb::SocketServer<SimpleWeb::WS> inside simpleweb/server_ws.hpp.
      • add SimpleWeb::WsClient = SimpleWeb::SocketClient<SimpleWeb::WS> inside simpleweb/client_ws.hpp.
      • add SimpleWeb::WssServer = SimpleWeb::SocketServer<SimpleWeb::WSS> inside simpleweb/server_wss.hpp.
      • add SimpleWeb::WssClient = SimpleWeb::SocketClient<SimpleWeb::WSS> inside simpleweb/client_wss.hpp.

Building the Debian Package

  • Create a build directory and move to it.
    $ mkdir build
    $ cd build
  • Configure the Makefile rules with /usr as the install prefix.
    $ cmake -DCMAKE_INSTALL_PREFIX=/usr ..
  • Build the library.
    $ make

    Note: you could speed up the build process with specifying the job count parameter using -jn where n is number of the jobs. (example: $ make -j4)

  • Create debian package using cpack.
    $ cpack

simple-web's People

Contributors

threeal avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

setoutsoft

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.