Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use it in wasmedge's cpp api? #30

Open
arcosx opened this issue Dec 16, 2021 · 4 comments
Open

Can I use it in wasmedge's cpp api? #30

arcosx opened this issue Dec 16, 2021 · 4 comments

Comments

@arcosx
Copy link

arcosx commented Dec 16, 2021

I want to embed a http request in wasm in a C++ program.Can you give me some advice?

@hydai
Copy link
Member

hydai commented Dec 17, 2021

Hi @arcosx,

This is for creating the wasm application, wasmedge provides the wasi-socket api support by default. All you need to do is use this SDK to compose your application, compile it to wasm, and then embed in our wasmedge.

Please refer to our example page for how to compile it. And just put the output wasm file in the our API. Thanks.

@arcosx
Copy link
Author

arcosx commented Dec 17, 2021

Thanks for the help, I tried to use http req and ran into the following problem.

cargo build --target wasm32-wasi --release
wasmedge target/wasm32-wasi/release/http_client.wasm

on master code I run the http_server

...
let res = request::get("http://127.0.0.1:1234/get", &mut writer).unwrap();
...

works fine

GET
Status: 200 OK
Headers {
}
....

but if I change to other url

let res = request::get("http://httpbin.org/get", &mut writer).unwrap();

It get error

➜  http_client git:(ad123cc) ✗ wasmedge target/wasm32-wasi/release/http_client.wasm
thread 'main' panicked at 'Expected error to be io::Error, got: IO(Error { kind: Unsupported, message: "operation not supported on this platform" })', src/main.rs:7:18
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[2021-12-17 22:50:47.407] [error] execution failed: unreachable, Code: 0x89
[2021-12-17 22:50:47.407] [error]     In instruction: unreachable (0x00) , Bytecode offset: 0x000156cb
[2021-12-17 22:50:47.407] [error]     When executing function name: "_start"

My OS

Linux version 5.11.0-42-generic (buildd@lcy01-amd64-013) (gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #46~20.04.1-Ubuntu SMP Tue Nov 30 14:20:24 UTC 2021

@hydai
Copy link
Member

hydai commented Dec 17, 2021

Hi @arcosx
The reason is that there is no DNS lookup function in WASM/WASI level. Once you use the domain name directly, there is no way to decode it to an raw ip address. That's why it failed.

We are still working on this. You can find a working PR in WasmEdge project.

@arcosx
Copy link
Author

arcosx commented Dec 17, 2021

Thank you again for your help, the answers were very helpful to me. Looking forward to the PR being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants