Running the samples
Run each sample from its own directory so relative paths resolve to the language library and its key files. The sample README lists the required packages. Before running a WebSocket example, obtain an RSA public JWK for the test service and save it as mesgd_pub.json, containing kty, n, and e. The well-known download URL printed in the older READMEs is not supplied by the current server or website.
The programs default to wss://echo.mesgd.org/ws. Lines that use ws://localhost:8080/ws are examples. They are not the port in mesgd.config.
The programs send a sealed registration frame followed by encrypted ping/pong frames. Running them against mesgd will fail because its listener expects JSON and does not implement that handshake. Use a test service that understands the sample protocol, or examine the code as a client-side cryptography example. Samples describes the compatibility limits.
Several sample programs also reference SDK wrappers that are absent from this checkout, so protocol compatibility is not their only limitation. Python, JavaScript, C, C++, Go, Lua, and OCaml have missing message-client modules, headers, or package wiring. Consult the individual language guides before treating a sample command as runnable. Kotlin has an account adapter but no ping/pong sample; Forth provides local cryptography only.
| Directory | Run |
|---|---|
01-python | pip install -r requirements.txt then python sample.py. Python 3.11 or newer |
02-javascript | npm install then npm start or node sample.mjs. Node.js 18 or newer |
03-java | javac -cp ../../ PKISample.java then java -cp .:../../ PKISample. JDK 17 or newer |
04-c | make then ./sample. OpenSSL 3, libwebsockets, and cJSON |
05-cpp | make then ./sample. A C++17 compiler, Boost 1.82 or newer, OpenSSL 3, nlohmann/json |
06-csharp | dotnet run. The .NET 8 SDK |
07-go | go mod tidy then go run .. Go 1.21 or newer |
08-rust | cargo run. Rust 1.75 or newer and OpenSSL headers |
09-php | composer install then php sample.php. PHP 8.1 or newer with openssl |
10-swift | swift run. macOS 13 or newer and Swift 5.9 or newer |
11-ruby | bundle install then ruby sample.rb. Ruby 3.0 or newer |
12-erlang | rebar3 compile, then rebar3 shell, then sample:main(). OTP 26 or newer and rebar3 |
13-perl | cpanm AnyEvent AnyEvent::WebSocket::Client JSON::PP Crypt::Perl Crypt::OpenSSL::RSA, then perl sample.pl. Perl 5.20 or newer |
14-haskell | cabal update, cabal build, cabal run pki-sample. GHC 9.4 or newer. The README also shows Stack |
15-lua | lua sample.lua after luaossl, lua-websockets, and lunajson are installed. Lua 5.4 or LuaJIT 2.1 |
16-ocaml | dune build then dune exec ./sample.exe. OCaml 4.14 or newer, opam, dune |
17-forth | gforth sample.f with OpenSSL's libcrypto on the library path. No WebSocket and no mesgd_pub.json |
MESGD_URL and MESGD_PUB_JWK override the WebSocket endpoint and the public-key path for the programs that read them. Forth reads neither.
An auth client is a different program. Its origin is HTTPS, and the calls are in Authentication. Do not point an auth client at wss://echo.mesgd.org/ws.