Enable socket-api recvmsg() and sendmsg() (#1042)
Implement socket-api `recvmsg()` and `sendmsg()` for wasm app, add sample and update document.
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
"socket-api" sample introduction
|
||||
================================
|
||||
# "socket-api" sample introduction
|
||||
|
||||
This sample demonstrates how to use WAMR socket-api to develop wasm network applications.
|
||||
Two wasm applications are provided: tcp-server and tcp-client, and this sample demonstrates
|
||||
@ -19,26 +18,30 @@ cmake ..
|
||||
make
|
||||
```
|
||||
|
||||
The file `tcp_server.wasm`, `tcp_client.wasm` and `iwasm` will be created.
|
||||
And also file `tcp_server` and `tcp_client` of native version are created.
|
||||
`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.
|
||||
|
||||
Note that iwasm is built with libc-wasi and lib-pthread enabled.
|
||||
> Note that iwasm is built with libc-wasi and lib-pthread enabled.
|
||||
|
||||
## Run workload
|
||||
|
||||
Start the tcp server, which opens port 1234 and waits for clients to connect.
|
||||
|
||||
```bash
|
||||
cd build
|
||||
./iwasm --addr-pool=0.0.0.0/15 tcp_server.wasm
|
||||
```
|
||||
|
||||
Start the tcp client, which connects the server and receives message.
|
||||
|
||||
```bash
|
||||
cd build
|
||||
./iwasm --addr-pool=127.0.0.1/15 tcp_client.wasm
|
||||
```
|
||||
|
||||
The output of client is like:
|
||||
|
||||
```bash
|
||||
[Client] Create socket
|
||||
[Client] Connect socket
|
||||
@ -54,4 +57,29 @@ Say Hi from the Server
|
||||
[Client] BYE
|
||||
```
|
||||
|
||||
`send_recv.wasm` contains a thread as a server and a thread as a client. They
|
||||
send and receive data via 127.0.0.1:1234.
|
||||
|
||||
```bash
|
||||
$ ./iwasm --addr-pool=127.0.0.1/0 ./send_recv.wasm
|
||||
```
|
||||
|
||||
The output is:
|
||||
|
||||
```bash
|
||||
Server is online ...
|
||||
Client is running...
|
||||
Start receiving.
|
||||
Start sending.
|
||||
Send 106 bytes successfully!
|
||||
Receive 106 bytes successlly!
|
||||
Data:
|
||||
The stars shine down
|
||||
It brings us light
|
||||
Light comes down
|
||||
To make us paths
|
||||
It watches us
|
||||
And mourns for us
|
||||
```
|
||||
|
||||
Refer to [socket api document](../../doc/socket_api.md) for more details.
|
||||
|
||||
Reference in New Issue
Block a user