Build and integrate JVR NetStack in minutes
Before building JVR NetStack, ensure you have:
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install build-essential cmake libssl-dev git
macOS:
brew install cmake openssl git
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl
Windows:
# Install Visual Studio 2019 or later
# Install CMake from https://cmake.org/
# Install OpenSSL from https://slproweb.com/products/Win32OpenSSL.html
Download the source code from GitHub:
git clone https://github.com/LoSkroefie/jvr-netstack.git
cd jvr-netstack
Use CMake to configure and build:
# Create build directory
mkdir build
cd build
# Configure
cmake ..
# Build
cmake --build .
# Optional: Build with examples and tests
cmake .. -DJVR_BUILD_EXAMPLES=ON -DJVR_BUILD_TESTS=ON
cmake --build .
Build Options:
-DJVR_BUILD_EXAMPLES=ON - Build example applications-DJVR_BUILD_TESTS=ON - Build test suite-DJVR_BUILD_JVRCURL=ON - Build JVRcurl toolVerify the installation by running the test suite:
./test_core
Expected output:
========================================
JVR NetStack Test Suite
========================================
test_error_suite:
Running: error_codes ... PASS
Running: error_strings ... PASS
All tests passed! ✅
Try the example applications:
# Simple HTTP GET request
./simple_http_get
# HTTP/2 multiplexing demo
./http2_multiplexing
# WebSocket chat client
./websocket_chat
# Circuit breaker demonstration
./circuit_breaker_demo
# Middleware pipeline
./middleware_pipeline
# Response caching
./response_caching
Add JVR NetStack as a subdirectory in your CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(MyApp)
# Add JVR NetStack
add_subdirectory(path/to/jvr-netstack)
# Your executable
add_executable(myapp main.c)
# Link against NetStack
target_link_libraries(myapp jvr_netstack)
# Include directories (optional if using subdirectory)
target_include_directories(myapp PRIVATE path/to/jvr-netstack/include)
Compile and link manually:
# Compile your application
gcc -c myapp.c -I./jvr-netstack/include -o myapp.o
# Link with JVR NetStack
gcc myapp.o -L./jvr-netstack/build -ljvr_netstack -lssl -lcrypto -o myapp
# Windows: Add ws2_32
gcc myapp.o -L./jvr-netstack/build -ljvr_netstack -lssl -lcrypto -lws2_32 -o myapp.exe
Create a file main.c:
#include "jvr/client.h"
#include <stdio.h>
int main() {
// Create HTTP client
jvr_client_t* client = jvr_client_create();
if (!client) {
fprintf(stderr, "Failed to create client\n");
return 1;
}
// Create GET request
jvr_request_t* request = jvr_request_create(
"GET",
"https://api.github.com/users/github"
);
// Add custom header
jvr_request_set_header(request, "User-Agent", "JVR-NetStack/1.0");
// Send request
jvr_response_t* response = jvr_client_send(client, request);
// Check response
if (response && response->status_code == 200) {
printf("Status: %d\n", response->status_code);
printf("Body: %.*s\n",
(int)response->body_size,
response->body);
} else {
printf("Request failed\n");
}
// Cleanup
jvr_response_destroy(response);
jvr_request_destroy(request);
jvr_client_destroy(client);
return 0;
}
# Using CMake
cmake .. && cmake --build .
./myapp
# Or manually
gcc main.c -I./jvr-netstack/include -L./jvr-netstack/build \
-ljvr_netstack -lssl -lcrypto -o myapp
./myapp
Customize client behavior
#include "jvr/client.h"
// Configure client with custom settings
jvr_client_config_t config = {
.prefer_http3 = true, // Prefer HTTP/3 if available
.prefer_http2 = true, // Fallback to HTTP/2
.connection_timeout_ms = 5000, // 5 second timeout
.max_concurrent_streams = 100, // HTTP/2 streams
.enable_compression = true, // Enable gzip/deflate
.follow_redirects = true, // Follow 3xx redirects
.max_redirects = 5 // Maximum redirect count
};
jvr_client_t* client = jvr_client_create_with_config(&config);
macOS: Set OPENSSL_ROOT_DIR environment variable:
export OPENSSL_ROOT_DIR=/usr/local/opt/openssl
cmake ..
Windows: Install from Win32OpenSSL and set paths in CMake.
Make sure to link against ws2_32.lib:
target_link_libraries(myapp jvr_netstack ws2_32)