Skip to content

Latest commit

 

History

History

async-wasi-socket-addr

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Retrieve the Socket Address

This example presents how to retrieve the socket address information asynchronously.

This example consists of two projects:

  • socket-addr is a wasm application, in which a group of socket addresses are set.

  • main-app is a host application that is responsible for creating a WasmEdge Vm instance, loading the wasm binary generated from socket-addr and finally running it over WasmEdge Runtime.

Now let's build and run this example.

  • Install rustup and Rust

    Go to the official Rust webpage and follow the instructions to install rustup and Rust.

    It is recommended to use Rust 1.71 or above in the stable channel.

    Then, add wasm32-wasi target to the Rustup toolchain:

    rustup target add wasm32-wasi
  • Install WasmEdge Runtime

    Refer to the Quick Install section of WasmEdge Runtime Book to install WasmEdge Runtime. Or, use the following command directly

    # NOTICE that the installation script needs `sudo` access
    
    # install wasmedge to the directory /usr/local/
    curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.14.0
    source $HOME/.wasmedge/env

    For users in China mainland (中国大陆地区), try the following command to install WasmEdge Runtime if failed to run the command above

    # NOTICE that the installation script needs `sudo` access
    
    bash install_zh.sh -v 0.14.0
    source $HOME/.wasmedge/env
  • Download example

    git clone git@github.com:second-state/wasmedge-rustsdk-examples.git
    cd wasmedge-rustsdk-examples/async-wasi-socket-addr
  • Build socket-addr

    cargo build -p socket-addr --target wasm32-wasi --release

    If the command runs successfully, socket-addr.wasm can be found in the directory of ./target/wasm32-wasi/release/.

  • Build and run main-app

    cargo run -p main-app -- ../target/wasm32-wasi/release/socket-addr.wasm

    If the command runs successfully, then the following message is printed out on the screen:

    [socket-addr] addr: 127.0.0.1:3000
    [socket-addr] addr: 127.0.0.1:3000
    [socket-addr] addr1: 0.0.0.0:80
    [socket-addr] addr2: 127.0.0.1:443
    [socket-addr] err: InvalidInput
    [socket-addr] err: Uncategorized
    [socket-addr] addr: None
    exit_code: 0