Is there any way we could get an example of how to do networking in emscripten (wasm)? I've been struggling with this issue for a long time now, even as I have already implemented something natively. I'm a total beginner at c++ and networking programming at this level, and I'm sure others are as well, so it would be extremely helpful.
The sockets tests have working code, see tests/test_sockets.py.
I finally figured out what was wrong with my code. I was trying to support both native and emscripten. I was using a library that read the WS headers for me on native, but the browser already does that and gives you back the raw message sent to you. All I needed to do was comment out the code from my library that read the WS headers, and everything was back in order!
May I know how to use that test_sockets.py ?
I have to port my c++ code containing socket code to WebAssembly.
You can run them with python tests/runner.py sockets. Replace sockets with sockets.test_X with a specific test to run just one, etc.
if I have to transpile my code say Test_client.cpp and Test_Server.cpp.
Do i have to make changes in Runner.py ? as it would be difficult for me because I know nothing about python.
I would just read the test code to see what it does. Even if you don't know python, you can see what function calls what, and in the end it emits some commands to emcc.py and others, etc.. Also, you can use EMCC_DEBUG=1 in the env to make it print out the emcc commands and their debug output (including the arguments they were called with).
For those who come by this issue: you may find this blog post "Introduction to Emscripten Sockets" helpful.
Server sockets? Listen and bind? :)
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 7 days. Feel free to re-open at any time if this issue is still relevant.
Most helpful comment
For those who come by this issue: you may find this blog post "Introduction to Emscripten Sockets" helpful.