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.
- 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)
- Boost.Asio or standalone Asio
- OpenSSL libraries
- Clone and checkout both
Simple Web Server
andSimple Websocket Server
to the latest release. - Merge both header files (
*.hpp
) of the library and put it underinclude/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
tohttp_client.hpp
. - rename
client_https.hpp
tohttps_client.hpp
. - rename
client_ws.hpp
tows_client.hpp
. - rename
client_wss.hpp
towss_client.hpp
. - rename
server_http.hpp
tohttp_server.hpp
. - rename
server_https.hpp
tohttps_server.hpp
. - rename
server_ws.hpp
tows_server.hpp
. - rename
server_wss.hpp
towss_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"
) - rename
- 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
toSIMPLEWEB_USE_STANDALONE_ASIO
. - change
HAVE_OPENSSL
toSIMPLEWEB_USE_STANDALONE_ASIO
. - change
HAVE_OPENSSL
toSIMPLEWEB_USE_OPENSSL
.
- change
- Add some namespaces as follow:
- add
SimpleWeb::HttpServer = SimpleWeb::SocketServer<SimpleWeb::HTTP>
insidesimpleweb/server_http.hpp
. - add
SimpleWeb::HttpClient = SimpleWeb::SocketClient<SimpleWeb::HTTP>
insidesimpleweb/client_http.hpp
. - add
SimpleWeb::HttpsServer = SimpleWeb::SocketServer<SimpleWeb::HTTPS>
insidesimpleweb/server_https.hpp
. - add
SimpleWeb::HttpsClient = SimpleWeb::SocketClient<SimpleWeb::HTTPS>
insidesimpleweb/client_https.hpp
. - add
SimpleWeb::WsServer = SimpleWeb::SocketServer<SimpleWeb::WS>
insidesimpleweb/server_ws.hpp
. - add
SimpleWeb::WsClient = SimpleWeb::SocketClient<SimpleWeb::WS>
insidesimpleweb/client_ws.hpp
. - add
SimpleWeb::WssServer = SimpleWeb::SocketServer<SimpleWeb::WSS>
insidesimpleweb/server_wss.hpp
. - add
SimpleWeb::WssClient = SimpleWeb::SocketClient<SimpleWeb::WSS>
insidesimpleweb/client_wss.hpp
.
- add
- Rename some macro definitions as follow:
- 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
wheren
is number of the jobs. (example:$ make -j4
) - Create debian package using cpack.
$ cpack