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

enable networking for emscripten #62

Open
belaviyo opened this issue Feb 9, 2023 · 1 comment
Open

enable networking for emscripten #62

belaviyo opened this issue Feb 9, 2023 · 1 comment
Labels
browser Web browser, JavaScript, and WASM integration enhancement New feature or request

Comments

@belaviyo
Copy link

belaviyo commented Feb 9, 2023

In case it helps improving the WASM port, I was able to perform a simple socket connection following these steps:

  1. add these headers to blink.c; reference
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/websocket.h>
#include <emscripten/threading.h>
#include <emscripten/posix_socket.h>

static EMSCRIPTEN_WEBSOCKET_T bridgeSocket = 0;
#endif
  1. make sure the WebSocket is ready when calling a method:
int main(int argc, char *argv[]) {
#ifdef __EMSCRIPTEN__
  if (!bridgeSocket) {
    bridgeSocket = emscripten_init_websocket_to_posix_socket_bridge("ws://localhost:8080");
    // Synchronously wait until connection has been established.
    uint16_t readyState = 0;
    do {
      emscripten_websocket_get_ready_state(bridgeSocket, &readyState);
      emscripten_thread_sleep(100);
    } while (readyState == 0);
  }
#endif
....
  1. Link with flags -lwebsocket.js -sPROXY_POSIX_SOCKETS -sUSE_PTHREADS -sPROXY_TO_PTHREAD reference
  2. Have a local server running; https://github.com/emscripten-core/emscripten/tree/main/tools/websocket_to_posix_proxy
./websocket_to_posix_proxy 8080
@belaviyo
Copy link
Author

belaviyo commented Feb 9, 2023

#22

@jart jart added enhancement New feature or request browser Web browser, JavaScript, and WASM integration labels Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
browser Web browser, JavaScript, and WASM integration enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants