rustup target add wasm32-wasiRUSTFLAGS="--cfg tokio_unstable" cargo build --target=wasm32-wasi
WebAssembly cannot execute socket(), bind(), or listen(). So instead, the WebAssembly runtime must open the socket and pass the file descriptor to the module. From there, WebAssembly may read(), write(), and handle connections.
- Install Enarx from https://github.com/enarx/enarx.
- Compile with
cargo build, optionally withcargo build --features "dbg"to see a lot of additional debugging output. - Use the provided Enarx.toml file:
enarx run --wasmcfgfile Enarx.toml target/wasm32-wasi/debug/tokio-echo-test.wasm.
- Download and install Wasmtime from https://github.com/bytecodealliance/wasmtime
- Optionally install Wasmtime with this script:
curl https://wasmtime.dev/install.sh -sSf | bash
- Optionally install Wasmtime with this script:
- Provide the socket file descriptor information on the command line:
wasmtime run --tcplisten 127.0.0.1:8080 --env FD_COUNT=3 target/wasm32-wasi/debug/tokio-echo-test.wasm.
Use Netcat to connect after "Listening" is displayed, nc localhost 8080.