Stream: general

Topic: Rust TcpStream::connect in wasmtime


view this post on Zulip Flynn (Apr 05 2024 at 23:31):

How do I make a tcp connection in wasi? My understanding is it should be supported now with preview 2?

I have a simple rust binary which I have compiled to target wasm32-wasi, but when I try and run it with wasmtime run I get
operation not supported on this platform

I have tried running it with wasmtime run -S tcp=y,allow-ip-name-lookup=y,preview2=y but no luck, any pointers here?

view this post on Zulip Alex Crichton (Apr 06 2024 at 01:23):

Support isn't in the standard library yet but you should be able to use the wasi crate

view this post on Zulip Flynn (Apr 06 2024 at 01:33):

Thanks for the reply @Alex Crichton , I found that crate a little after sending that message. I am using the 'instance_network()` call to get the network but I am getting the following error running it with wasmtime 19.0.1:

1: unknown import: `wasi:sockets/network@0.2.0::[resource-drop]network` has not been defined

with these flags -S tcp=y,inherit-network=y,preview2=y

view this post on Zulip Flynn (Apr 06 2024 at 01:36):

Looks like i need to use wasm-tools to build it with the adapter

view this post on Zulip Alex Crichton (Apr 06 2024 at 01:41):

yeah you'll need to be sure to use a component when using the wasi crate

view this post on Zulip Flynn (Apr 06 2024 at 02:11):

thanks for the help

view this post on Zulip Flynn (Apr 06 2024 at 02:15):

so at some point this will all be abstracted away in the standard library? Is there any point adding support for wasi via the wasi crate to a http request library?

view this post on Zulip Alex Crichton (Apr 06 2024 at 16:35):

yep all planned in due time :)

view this post on Zulip Ryan Levick (rylev) (Apr 08 2024 at 13:09):

While socket support will be abstracted away in the std library support, there will be need to get wasi:http support into http client libraries.

Http calls that go through the socket interfaces will work, but there are advantages to having http go through the higher level wasi:http interfaces


Last updated: Nov 22 2024 at 17:03 UTC