emscripten-core / emscripten-core/emscripten
WebSocket API similar to POSIX socket API
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Hi
We are having some trouble in porting our middleware (https://github.com/eclipse-zenoh) to run on emscripten and WebSockets.
For the server side, we already have a WebSocket server able to receive messages and reply to them (https://github.com/eclipse-zenoh/zenoh). It is Rust based and leverages on https://github.com/snapview/tokio-tungstenite. We are able to have Rust client and server side to exchange messages over WebSocket.
Now we are in the process of porting our C implementation (https://github.com/eclipse-zenoh/zenoh-pico), and we have some trouble doing it.
In particular, we found that the [callback-based API](https://github.com/emscripten-core/emscripten/blob/main/test/websocket/websocket.c) is not really helping us, so we wondered if an API similar to the POSIX one is available (`send/recv` kind of).
That approach matches better with our session establishment, as we need there some synchronous receiving and sending of messages. We tried to address this requirement by having the callbacks and receiving function to synchronize with a status variable and `sleep` but it seems that things are not really working (it seems to us that either the callback or the receiving function are not yielding it on sleep).
We took a look at the [TCP echo client](https://github.com/emscripten-core/emscripten/blob/main/test/websocket/tcp_echo_client.c), but it seems to us that we have to additionally run the `websocket_to_posix_proxy`. It would not fit our specific scenario.
Any thoughts on this?
**Version of emscripten/emsdk:**
```bash
$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.28-git
clang version 16.0.0 (https://github.com/llvm/llvm-project.git ea4be70cea8509520db8638bb17bcd7b5d8d60ac)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/Cellar/emscripten/3.1.28/libexec/llvm/bin
```
**Failing command line in full:**
N/A
**Full link command and output with `-v` appended:**
N/A
Contributor guide
Assessment
This issue has not been assessed yet.