Yurii Sokolovskyi 8708b8e54b Initial commit | 5 miesięcy temu | |
---|---|---|
.. | ||
http_client | 5 miesięcy temu | |
http_server | 5 miesięcy temu | |
nonblock_http_client | 5 miesięcy temu | |
README.md | 5 miesięcy temu | |
get_addrinfo.rs | 5 miesięcy temu | |
nonblock_tcp_stream.rs | 5 miesięcy temu | |
poll_tcp_listener.rs | 5 miesięcy temu | |
socket_addr.rs | 5 miesięcy temu | |
tcp_listener.rs | 5 miesięcy temu | |
tcp_stream.rs | 5 miesięcy temu | |
try_dns.rs | 5 miesięcy temu | |
try_sock_opt.rs | 5 miesięcy temu | |
udp_reverse.rs | 5 miesięcy temu | |
udp_socket.rs | 5 miesięcy temu |
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