This repository has been archived. The development has been succeeded/continued in https://github.com/xminent/net.
A small network library written for use with my library Ekizu
- ssl::Client: A TCP/UDP Client with optional SSL support.
- http::Client: An HTTP(S) client.
- ws::Client: A WebSocket client.
- CMake (version >= 3.15)
- Compiler with C++20 support, i.e. MSVC, GCC, Clang
This library uses CPM.cmake to manage dependencies. It is an amazing package manager for CMake projects and allows us to install the entire library using the following commands:
git clone https://www.github.com/xminent/ekisocket
cd ekisocket
make install
From there you can simply integrate it into your CMake project like so:
find_package(ekisocket REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE ekisocket::ekisocket)
#include <ekisocket/SslClient.hpp>
#include <iostream>
int main()
{
// Access a TCP server found in localhost:8080.
ekisocket::ssl::Client client("localhost", 8080, /* use_ssl */ false, /* use_udp = false */);
client.connect();
client.send("Hello World!");
// Gracefully closes on destruction.
}
#include <ekisocket/HttpClient.hpp>
#include <iostream>
int main()
{
// Simple GET request to an API endpoint.
const auto res = ekisocket::http::get("https://catfact.ninja/fact");
std::cout << res.body << '\n';
}
#include <ekisocket/WebSocketClient.hpp>
#include <iostream>
int main()
{
// Simple GET request to an API endpoint.
ekisocket::ws::Client client("wss://gateway.discord.gg/?v=10&encoding=json");
client.set_on_message([](const ekisocket::ws::Message& msg){
std::cout << "Received message: " << msg.data << '\n';
});
// Blocks until disconnected. (Automatic reconnect is on by default).
client.start();
// Automatic reconnect can be turned off by doing:
// client.set_automatic_reconnect(false);
// For unblocking, run:
// client.start_async();
}