Add timeout send/recv and multicast client/server socket examples (#1519)
Add a couple of socket examples that can be used with WAMR: - The `timeout_client` and `timeout_server` examples demonstrate socket send and receive timeouts using the socket options - The `multicast_client` and `multicast_server` examples demonstrate receiving multicast packets in WASM And add several macro controls for `socket_opts` example.
This commit is contained in:
@ -93,20 +93,73 @@ Data:
|
||||
|
||||
`socket_opts.wasm` shows an example of getting and setting various supported socket options
|
||||
```bash
|
||||
$ ./iwasm ./socket_opts.wasm
|
||||
$ ./iwasm socket_opts.wasm
|
||||
```
|
||||
|
||||
The output describes the different socket options that are set & retrieved, like so:
|
||||
The output is:
|
||||
```bash
|
||||
[Client] Create TCP socket
|
||||
[Client] Create UDP socket
|
||||
[Client] Create UDP IPv6 socket
|
||||
SO_RCVTIMEO tv_sec is expected
|
||||
SO_RCVTIMEO tv_usec is expected
|
||||
setsockopt SO_RCVTIMEO result is expected
|
||||
getsockopt SO_RCVTIMEO result is expected
|
||||
...
|
||||
[Client] Close sockets
|
||||
```
|
||||
|
||||
The `timeout_client.wasm` and `timeout_server.wasm` examples demonstrate socket send and receive timeouts using the socket options. Start the server, then start the client.
|
||||
|
||||
```bash
|
||||
$ ./iwasm --addr-pool=0.0.0.0/15 timeout_server.wasm
|
||||
```
|
||||
|
||||
The output is:
|
||||
|
||||
```bash
|
||||
Wait for client to connect
|
||||
Client connected, sleeping for 10s
|
||||
Shuting down
|
||||
```
|
||||
|
||||
```bash
|
||||
$ ./iwasm --addr-pool=127.0.0.1/15 --heap-size=10000000 timeout_client.wasm
|
||||
```
|
||||
|
||||
The output is:
|
||||
|
||||
```bash
|
||||
Waiting on recv, which should timeout
|
||||
Waiting on send, which should timeout
|
||||
Success. Closing socket
|
||||
```
|
||||
|
||||
The `multicast_client` and `multicast_server` examples demonstrate receiving multicast packets in WASM. Start the client and then the server with a multicast IP address and port.
|
||||
|
||||
```bash
|
||||
$ ./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm <Multicast IP> <Port>
|
||||
$ ./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm 224.0.0.1
|
||||
$ ./iwasm --addr-pool=0.0.0.0/0,::/0 multicast_client.wasm FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2
|
||||
```
|
||||
|
||||
The output should be
|
||||
|
||||
```bash
|
||||
Joined multicast group. Waiting for datagram...
|
||||
Reading datagram message...OK.
|
||||
The message from multicast server is: "Test message"
|
||||
```
|
||||
|
||||
```bash
|
||||
$ ./multicast_server <Multicast IP> <Port>
|
||||
$ ./multicast_server 224.0.0.1
|
||||
$ ./multicast_server FF02:113D:6FDD:2C17:A643:FFE2:1BD1:3CD2
|
||||
```
|
||||
|
||||
The output should be
|
||||
|
||||
```bash
|
||||
Datagram sent
|
||||
```
|
||||
|
||||
### Domain name server resolution
|
||||
|
||||
`addr_resolve.wasm` demonstrates the usage of resolving a domain name
|
||||
|
||||
Reference in New Issue
Block a user