emscripten-core / emscripten-core/emscripten
Setting the `Module['websocket']` at runtime does not work since version 3.1.71
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Since version 3.1.71, setting the `Module['websocket']` at runtime does not work anymore.
I tried setting `Module['websocket']` using `emscripten_run_script` and `EM_JS`.
I think it could be linked to https://github.com/emscripten-core/emscripten/pull/22774.
**Version of emscripten/emsdk:**
```
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.72 (437140d149d9c977ffc8b09dbaf9b0f5a02db190)
clang version 20.0.0git (https:/github.com/llvm/llvm-project 1c4caece05f1885ba6ed80755d6b5de1b9f99579)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
```
**Build command:**
```
emcc test.cpp -o index.html -sEXPORTED_FUNCTIONS=_main -sSOCKET_DEBUG=1
```
**Source test.cpp:**
```cpp
#include
#include
#include
#include
#include
#include
#include
int main() {
emscripten_run_script("Module['websocket'] = {url: 'wss://MY_URL', subprotocol: 'binary'}");
int _fd = ::socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in server;
memset(&server, 0, sizeof(server));
server.sin_addr.s_addr = inet_addr("172.29.1.0");
server.sin_family = AF_INET;
server.sin_port = htons(443);
auto res = ::connect(_fd, (struct sockaddr*)&server , sizeof(server));
std::cout << "!! " << res << " " << errno << std::endl;
return 0;
}
```
**Result with 3.1.72:**
```
websocket: connect: ws://172.29.1.0:443/, binary
!! -1 23
```
**Result with 3.1.72, using the `emcc` option `-sWEBSOCKET_URL=wss://MY_URL`:**
```
websocket: connect: wss://MY_URL, binary
websocket: adding peer: 172.29.1.0:443
!! 0 0
```
**Result with 3.1.70:**
```
websocket: connect: wss://MY_URL, binary
websocket: adding peer: 172.29.1.0:443
!! 0 0
```
Contributor guide
Assessment
This issue has not been assessed yet.