1Prerequisites

Before building JVR NetStack, ensure you have:

  • ✅ C compiler (GCC, Clang, or MSVC)
  • ✅ CMake 3.10 or higher
  • ✅ OpenSSL development libraries
  • ✅ Git (for cloning the repository)

Installing Dependencies:

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

2Clone the Repository

Download the source code from GitHub:

git clone https://github.com/LoSkroefie/jvr-netstack.git
cd jvr-netstack

3Build the Library

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 tool

4Run Tests (Optional)

Verify 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! ✅

5Run Examples (Optional)

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

Integrating into Your Project

Using CMake (Recommended)

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)

Manual Compilation

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

Your First Application

Simple HTTP GET Request

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;
}

Compile and Run

# 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

Advanced Configuration

Client Configuration

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);

Next Steps

📚

Explore Examples

Check out comprehensive examples covering all major features.

View Examples
📖

API Reference

Detailed documentation of all functions and data structures.

Read API Docs
💡

Learn Advanced Features

Discover connection migration, 0-RTT, metrics, and more.

View Features

Troubleshooting

OpenSSL not found

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.

Link errors on Windows

Make sure to link against ws2_32.lib:

target_link_libraries(myapp jvr_netstack ws2_32)

Need Help?

Contact us: jvrsoftware@gmail.com

GitHub Issues: Report a bug