|
|
@@ -18,14 +18,21 @@ cmake ..
|
|
|
make
|
|
|
```
|
|
|
|
|
|
-`iwasm` and three Wasm modules, `tcp_server.wasm`, `tcp_client.wasm`, `send_recv.wasm`
|
|
|
-will be generated. And their corresponding native version, `tcp_server`,
|
|
|
-`tcp_client`, `send_recv` are generated too.
|
|
|
+`iwasm` and the following Wasm modules (along with their corresponding native version) will be generated:
|
|
|
+ * `addr_resolve.wasm`, `addr_resolve`
|
|
|
+ * `send_recv.wasm`, `send_recv`
|
|
|
+ * `socket_opts.wasm`, `socket_opts`
|
|
|
+ * `tcp_client.wasm`, `tcp_client`
|
|
|
+ * `tcp_server.wasm`, `tcp_server`
|
|
|
+ * `udp_client.wasm`, `udp_client`
|
|
|
+ * `udp_server.wasm`, `udp_server`
|
|
|
|
|
|
> Note that iwasm is built with libc-wasi and lib-pthread enabled.
|
|
|
|
|
|
## Run workload
|
|
|
|
|
|
+### TCP client/server
|
|
|
+
|
|
|
Start the tcp server, which opens port 1234 and waits for clients to connect.
|
|
|
|
|
|
```bash
|
|
|
@@ -82,6 +89,8 @@ Data:
|
|
|
And mourns for us
|
|
|
```
|
|
|
|
|
|
+### Socket options
|
|
|
+
|
|
|
`socket_opts.wasm` shows an example of getting and setting various supported socket options
|
|
|
```bash
|
|
|
$ ./iwasm ./socket_opts.wasm
|
|
|
@@ -98,4 +107,53 @@ SO_RCVTIMEO tv_usec is expected
|
|
|
[Client] Close sockets
|
|
|
```
|
|
|
|
|
|
+### Domain name server resolution
|
|
|
+
|
|
|
+`addr_resolve.wasm` demonstrates the usage of resolving a domain name
|
|
|
+```
|
|
|
+$ ./iwasm --allow-resolve=*.com addr_resolve.wasm github.com
|
|
|
+```
|
|
|
+
|
|
|
+The command displays the host name and its corresponding IP address:
|
|
|
+```
|
|
|
+Host: github.com
|
|
|
+IPv4 address: 140.82.121.4 (TCP)
|
|
|
+```
|
|
|
+
|
|
|
+### UDP client/server
|
|
|
+
|
|
|
+Start the UDP server, which opens port 1234 and waits for clients to send a message.
|
|
|
+
|
|
|
+```bash
|
|
|
+cd build
|
|
|
+./iwasm --addr-pool=0.0.0.0/15 udp_server.wasm
|
|
|
+```
|
|
|
+
|
|
|
+Start the tcp client, which sends a message to the server and waits for the response.
|
|
|
+
|
|
|
+```bash
|
|
|
+cd build
|
|
|
+./iwasm --addr-pool=127.0.0.1/15 udp_client.wasm
|
|
|
+```
|
|
|
+
|
|
|
+The output of client is like:
|
|
|
+
|
|
|
+```bash
|
|
|
+[Client] Create socket
|
|
|
+[Client] Client send
|
|
|
+[Client] Client receive
|
|
|
+[Client] Buffer recieved: Hello from server
|
|
|
+[Client] BYE
|
|
|
+```
|
|
|
+
|
|
|
+The output of the server is like:
|
|
|
+```
|
|
|
+[Server] Create socket
|
|
|
+[Server] Bind socket
|
|
|
+[Server] Wait for clients to connect ..
|
|
|
+[Server] received 17 bytes from 127.0.0.1:60927: Hello from client
|
|
|
+```
|
|
|
+
|
|
|
+## Documentation
|
|
|
+
|
|
|
Refer to [socket api document](../../doc/socket_api.md) for more details.
|