emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.88k stars 3.32k forks source link

tests/websocket/tcp_echo_client.cpp not works #11627

Open yylittlefish opened 4 years ago

yylittlefish commented 4 years ago

Hi, I tried to setup a wasm socket client and communicate with a TCP socket server. it seems wasm socket could not communicate directly with TCP socket, I need to setup a socket proxy server to make it work. I checked the guide here https://emscripten.org/docs/porting/networking.html#full-posix-sockets-over-websocket-proxy-server and tried to run the sample in tests/websocket/tcp_echo_client.cpp, but it not works. My steps is :

  1. build tools/websocket_to_posix_proxy: mkdir build cd build cmake .. make then I got the binary file websocket_to_posix_proxy in build folder

  2. build tests/websocket/tcp_echo_client.cpp with command: emcc tcp_echo_client.cpp -lwebsocket.js -s PROXY_POSIX_SOCKETS=1 -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1 -o client.js

  3. run the proxy with command: ./websocket_to_posix_proxy 8080 there's log: websocket_to_posix_proxy server is now listening for WebSocket connections to ws://localhost:8080/

  4. run client with command: node --experimental-wasm-threads --experimental-wasm-bulk-memory client.js

the issue is: emscripten_websocket_get_ready_state(bridgeSocket, &readyState); the readyState always 0. is anybody know the reason? is there any issue with my steps? thank you very much!

themighty1 commented 3 years ago

@yylittlefish , I encountered the exact same issue as you did. A small consolation is that it WORKS in Chrome 92 when I build with

emcc tcp_echo_client.cpp -lwebsocket.js -s PROXY_POSIX_SOCKETS=1 -s USE_PTHREADS=1 -s PROXY_TO_PTHREAD=1 -o client.html

And then load client.html in Chrome Related to another issue I filed https://github.com/emscripten-core/emscripten/issues/14750

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.