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

Is there away to allow an application to open a TCP socket? #1110

Closed
gkorland opened this issue Dec 26, 2019 · 7 comments
Closed

Is there away to allow an application to open a TCP socket? #1110

gkorland opened this issue Dec 26, 2019 · 7 comments
Labels
priority-medium Medium priority issue ❓ question I've a question!

Comments

@gkorland
Copy link

We have a C application that opens a TCP socket, is there a way to allow/control which TCP can be opened?

@gkorland gkorland added the ❓ question I've a question! label Dec 26, 2019
@Neightro
Copy link

Neightro commented Apr 27, 2020

I'm just a lurker here; I came here looking for information on the same subject. My understanding (and I'm still quite unfamiliar with WebAssembly) is that it's not possible to open just any socket on the system from WebAssembly; you will have to open a socket from outside WebAssembly and then pass it to the runtime. You will then be able to read and write the socket via WASI; This thread implies that it functions similarly to POSIX systems, wherein the socket is manipulated like a file descriptor.

I'm not sure if Wasmer currently supports sockets; I can see constants relating to sockets in the Rust wasmer-wasi documentation, though I've yet to find any specific information on how to use sockets with WASI. I would appreciate someone with more knowledge could help fill in that gap in my knowledge.

I would also suggest looking into the documentation for Wasmer; you might find more detailed information than with which I am able to provide you. I'm going to do some more reading; I will update if I learn more details; I will include links if I come across anything relevant.

@MarkMcCaskey
Copy link
Contributor

@Neightro Thanks! That's good information.

Sorry about the lack of response to this issue, it must have fallen through the cracks.

Yeah, opening sockets depends on your ABI providing imports that let you do so. Our Emscripten implementation, which is minimally/not sandboxed allows programs to use sockets. Additionally, you can do the "no ABI", or rather the "custom ABI" approach where you implement a socket API yourself with imports so that it works with your program.

I'm not sure if Wasmer currently supports sockets; I can see constants relating to sockets in the Rust wasmer-wasi documentation, though I've yet to find any specific information on how to use sockets with WASI. I would appreciate someone with more knowledge could help fill in that gap in my knowledge.

I believe we have some experimental code in kernel-net, but I'm not familiar with it. Sockets are not yet well defined in WASI so we don't support them yet. When WASI gets to a place where the CG can start discussing socket APIs in more depth, we'll definitely prioritize the development and implementation of those APIs.

It is possible to use the WASI virutal filesystem to implement networked files (the same way we implemented the framebuffer). It's a hack but it's something you could do today if you wanted to have networked WASI applications in Wasmer. The biggest issue with the hacks such as custom imports or special files is that no existing socket code will "just work" with it.

@CooperLi
Copy link

@MarkMcCaskey any updates for socket support now despite the wasi virtual fs network files implementation? : )

@syrusakbary
Copy link
Member

We have a work-in-progress branch that fully supports sockets:

https://github.com/wasmerio/wasmer/tree/wasio

@Hywan
Copy link
Contributor

Hywan commented Jul 15, 2021

We have another branch (a reb00t) with socket and epoll support, https://github.com/wasmerio/wasmer/tree/wasio-reboot-event-based-socket2/lib/wasi-experimental-network/examples. There is a Rust frontend, and implementation in WASI libc and Zig is also coming, https://github.com/ziglang/zig/compare/master...Hywan:feat-wasi-experimental-networking?expand=1. socket.h and epoll.h are compiling and working.

Note: It's super experimental for the moment. The idea is not to make it the new standard but to experiment as a community, and see what's missing, what are the challenges etc.

@Hywan Hywan self-assigned this Jul 15, 2021
@Amanieu Amanieu added the priority-medium Medium priority issue label Oct 20, 2021
@AlmogBaku
Copy link

Any update on this?

@epilys
Copy link
Contributor

epilys commented Jun 21, 2022

This was added in 62de9c5 which has been merged to master, and will be part of the 3.0 release

@epilys epilys closed this as completed Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-medium Medium priority issue ❓ question I've a question!
Projects
None yet
Development

No branches or pull requests

9 participants