Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify the tcp_server example to support target_os = "wasi"
Use the `LISTEN_FDS` mechanism to use pre-opened sockets. Especially for `wasm32-wasi` there is no other way to get access to sockets, than to use pre-opened sockets. Because `wasm32-wasi` does not yet return `TcpListener::local_addr()`, an unspecified IP address and port will be returned and displayed. ``` $ cargo +nightly build --target wasm32-wasi --release --example tcp_server --features="os-poll net" Compiling cfg-if v1.0.0 Compiling wasi v0.10.2+wasi-snapshot-preview1 Compiling log v0.4.14 Compiling libc v0.2.112 Compiling ppv-lite86 v0.2.15 Compiling wasi v0.11.0+wasi-snapshot-preview1 Compiling getrandom v0.2.3 Compiling rand_core v0.6.3 Compiling env_logger v0.8.4 Compiling rand_chacha v0.3.1 Compiling mio v0.8.0 (/home/harald/git/mio) Compiling rand v0.8.4 Finished release [optimized] target(s) in 2.92s $ wasmtime run --tcplisten 127.0.0.1:9000 --env 'LISTEN_FDS=1' target/wasm32-wasi/release/examples/tcp_server.wasm Using preopened socket FD 3 You can connect to the server using `nc`: $ nc <IP> <PORT> You'll see our welcome message and anything you type will be printed here. ``` Signed-off-by: Harald Hoyer <harald@profian.com>
- Loading branch information