r/C_Programming • u/Just_Jaguar3701 • 7d ago
Question Can you use your own implementations of HTTP/WebSockets in a browser using wasm?
Hello,
I wanted to make my own network stack implementation (http and websockets) just for learning purposes, so my question is knowing that were using sockets can we use that in the browser after compiling to a wasm? Or will it only work natively without serving to a browser?
9
Upvotes
10
u/realhumanuser16234 7d ago
no, you get the protocols supported by your browser. not a raw tcp connection
1
u/laggySteel 5d ago
How are you compiling to WASM ? I would love to use that, as Im also interested in C to wasm.
1
u/bluejacket42 7d ago
Any reason to no use just plan c instead of wasm
1
u/Hoshiqua 7d ago
Yes, I'm doing that for my game project. But it's not as simple as using TCP sockets in a WASM program. The WASM itself cannot open sockets, only the JS layer can, and those are of course limited to WebSockets, meaning if your server is also made in handrolled C (like mine) you'll have to implement the WebSocket handshake and frames yourself.
I've had good success getting Claude to guide me through the websocket-specific stuff, and I'm sure there are well made guides for it.