Thank you Andre. I tried running a simple TCP server in node after 
compiling to wasm. It gave me this error on the 'accept' call: 

> TypeError: Cannot read property 'stream' of undefined at Object.accept

Any leads on how to fix this or is this the case of using a blocking call? 
Also, the same code gives an error in the browser that 'Listen is not 
supported'.

On Monday, September 3, 2018 at 3:21:52 PM UTC+5:30, Floh wrote:
>
> Threads: don't know
>
> Sockets: emscripten has a socket-over-WebSockets 'emulation' which allows 
> to write a TCP-socket-wrapper which shares most of the code with a 'native' 
> socket version, but with some (pretty hefty) caveats:
>
> - emscripten sockets always operate in non-blocking mode, if your existing 
> socket code uses blocking mode anywhere it needs to be rewritten for 
> non-blocking (since your code uses threads too, it sounds like it is using 
> blocking sockets inside threads to avoid blocking the main thread, AFAIK 
> this won't be portable to emscripten, even once threads are available).
>
> - since emscripten sockets use WebSockets under the hood, your server 
> needs to be able to handle WebSocket connections instead of 'raw' TCP 
> socket connections
>
> - WebSockets are message-oriented, not stream-oriented under the hood 
> (every send() you do corresponds to exactly one recv(), unlike TCP 
> streams), if your code already properly handles TCP socket data streams, 
> this shouldn't be an issue, but it's better to be aware of it, since the 
> native- and WebSocket-version will behave slightly different on the 
> receiver-side).
>
> In general, don't expect any existing socket code to simply compile and 
> work on emscripten. You'll most likely need to rewrite the low-level socket 
> wrapper code, and on the server-side add a WebSocket-to-TCP proxy, but you 
> can it in a way shares a lot of code between the emscripten- and 
> native-version, both on the client- and server-side.
>
> Cheers!
> -Floh
>
> On Sunday, 2 September 2018 19:27:51 UTC+2, Varun Kumar wrote:
>>
>> I have a C library which uses sockets and threads. I want the library to 
>> be available for the developers to use when building apps which run in 
>> browsers and on node, and also when developing hybrid apps using cordova. I 
>> read that the SharedArrayBuffer support is not there yet in the stable 
>> versions of the browsers. I could not completely understand how would 
>> sockets work. So, could you please let me know whether is it the right 
>> approach to use WebAssembly for the above mentioned use case. Are sockets 
>> and threads supported or how long will it take for support for these 
>> features to come so that these could be used in a production environment?
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to