Git Product home page Git Product logo

incppect's Introduction

Build Status

incppect

Inspect C++ memory in the browser

Description

This is a small library that allows a C++ native application to stream memory bits to one or more websocket clients. This functionality can be used to conveniently inspect the internal state of the native application from a browser.

Incppect starts a simple HTTP(S)/WebSocket server in your application that accepts external connections. When a client connects, incppect serves the static content (HTML/JS) from a user-specified location, as well as the built-in incppect JS client incppect.js. The client opens a websocket connection back to the application and starts requesting custom data. The data is streamed back to the client over the websocket. The usage/visualization of the received data is entirely up to the client.

The HTTP(S)/WebSocket server is implemented via the uWebSocket library (included in the project as a submodule).

Examples:

incppect-balls2d

Checkout the examples folder for more samples.

Other projects:

Sample usage (HTTP):

Example: hello-browser

In your C++ program add something along these lines:

#include "incppect/incppect.h"

// start the web server in a dedicated thread
auto & incppect = Incppect<false>::getInstance();
incppect.runAsync(...);

int32_t some_var;
float some_arr[10];
    
// define variables that can be requested from the web clients
incppect.var("path0", [&](auto ) { return Incppect<false>::view(some_var); });
incppect.var("path1[%d]", [&](auto idxs) { return Incppect<false>::view(some_arr[idxs[0]]); });

In your web client:

<script src="incppect.js"></script>

<script>
    incppect.render = function() {
        // request C++ data
        var some_var = this.get_int32('path0');
        var some_arr_element = this.get_int32_arr('path1[%d]', 5);
        
        // do something with it
        ...
    }
    
    incppect.init();
</script>

Sample usage (HTTPS):

Example: hello-browser-ssl

In your C++ program add something along these lines:

#include "incppect/incppect.h"

// start the web server in a dedicated thread
auto & incppect = Incppect<true>::getInstance();

// provide valid SSL certificate
incppect::Parameters parameters;
parameters.sslKey = "key.pem";
parameters.sslCert = "cert.pem";

incppect.runAsync(parameters);

int32_t some_var;
float some_arr[10];
    
// define variables that can be requested from the web clients
incppect.var("path0", [&](auto ) { return Incppect<true>::view(some_var); });
incppect.var("path1[%d]", [&](auto idxs) { return Incppect<true>::view(some_arr[idxs[0]]); });

In your web client:

<script src="incppect.js"></script>

<script>
    incppect.render = function() {
        // request C++ data
        var some_var = this.get_int32('path0');
        var some_arr_element = this.get_int32_arr('path1[%d]', 5);
        
        // do something with it
        ...
    }
    
    // notice we use secure web-socket
    incppect.ws_uri = 'wss://' + window.location.hostname + ':' + window.location.port + '/incppect';
    
    incppect.init();
</script>

Build instructions

Linux and Mac OS

git clone https://github.com/ggerganov/incppect
cd incppect
git submodule update --init
mkdir build && cd build
cmake ..
make

incppect's People

Contributors

ggerganov avatar

Watchers

 avatar

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.