-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
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 #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:
#include <emscripten/emscripten.h>
#include <errno.h>
#include <iostream>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <string.h>
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
Metadata
Metadata
Assignees
Labels
No labels