Yurii Sokolovskyi 8708b8e54b Initial commit | il y a 5 mois | |
---|---|---|
.. | ||
http_client | il y a 5 mois | |
http_server | il y a 5 mois | |
nonblock_http_client | il y a 5 mois | |
README.md | il y a 5 mois | |
get_addrinfo.rs | il y a 5 mois | |
nonblock_tcp_stream.rs | il y a 5 mois | |
poll_tcp_listener.rs | il y a 5 mois | |
socket_addr.rs | il y a 5 mois | |
tcp_listener.rs | il y a 5 mois | |
tcp_stream.rs | il y a 5 mois | |
try_dns.rs | il y a 5 mois | |
try_sock_opt.rs | il y a 5 mois | |
udp_reverse.rs | il y a 5 mois | |
udp_socket.rs | il y a 5 mois |
Here are some examples for running network socket programs in WasmEdge. The applications are written in Rust.
You need to install Rust and WasmEdge before you try to compile and run the following examples.
This is a example of using WasmEdge as a socket client.
cargo run --example tcp_stream
Set up a server on your localhost with ncat.
ncat -kvlp 1234
Copy wasm into WasmEdge directory and run it. WasmEdge would send message "hello" to a server at localhost:1234
.
$ cp <path-to-wasmedge_wasi_socket>/target/wasm32-unknown-unknown/debug/examples/tcp_stream.wasm <path-to-wasmedge>
$ ./wasmedge --env PORT=1234 ./tcp_stream.wasm
connect to 127.0.0.1:1234
sending hello message...
The server should get the message "hello".
$ ncat -kvlp 1234
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Listening on :::1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 127.0.0.1.
Ncat: Connection from 127.0.0.1:56366.
hello
This is a example of using wasmedge as a socket server.
cargo run --example tcp_listener
Set up a client on your localhost with ncat.
Send any message, then send EOF with . The server would send back the reversed message.
For example, if the client send message "hello", the client would receive the response "olleh".
$ ncat -v 127.0.0.1 1234
Ncat: Version 7.91 ( https://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:1234.
hello
olleh