2

I have a project need using websocket (or named pipe) in browser to communicate with native program. (Is it feasible by Webassembly?)

I have wrote a c++ websocket with Boost Library and would like to compile it to wasm.

But I have no idea how to use Boost Lib(not header only) with Emscripten.

I try to bulid Boost Lib by this: Using Boost with Emscripten

However, how should I link the lib when compiling project with Emscripten?

Thanks!

SAng
  • 21
  • 1
  • 4

2 Answers2

0

I think you have to go with a different solution to use websockets with wasm. You might want to try using websockets in javascript and connect it with your c++ code.

Another answer with an example on how to do this:

https://stackoverflow.com/a/44637040/3042747

emscripten documentation for c++/javascript interaction:

https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html

-1

Yesterday I think that you cannot do it, because in browser you limited with browser API. And I know only websocket.

But today I found that I'm not right - exists WebRtc data channel, so possible emscripten library implemented somehow C 'socket' API.

IMHO it's too difficult. Why do you implement web socket protocol, using probably functionally limited implementation of socket ? You already have working websocket in javascript API !

To communication between browser sandbox and external world, you can call from webassembly program javasript functions that call websocket API.

In google io codelab explained how to write C program that not use any C library. In the case wasm code is tiny.

Please see example code in my question:How to call from webassembly websocket API?

Igor
  • 1
  • 1
  • 6
  • 1
    There is a [sugested edit](https://stackoverflow.com/review/suggested-edits/16461439) by [Igor](https://stackoverflow.com/users/8179827/igor). Is it your account? In this case, please [ask for merging your accounts](https://stackoverflow.com/help/merging-accounts), so you can edit your own posts without approval. – Melebius Jun 19 '17 at 09:37
  • Thank you for your help! The purpose is hiding communication mechanism from users for avoiding some attacks as much as possible. If use javascript to implement websocket ,the code is plain code.(however,wasm is binary code) – SAng Jun 20 '17 at 02:19
  • Hello Igor! There is no "Side_Module" flag in your compilation , and it would output Html & Js file. However ,why the style of using module seem Side_Module? – SAng Jul 18 '17 at 09:09
  • Really I don't know emcc flags - I get the command line from google io codelab. ;-) Welcome to add comments to my websocket example. Mode -s ONLY_MY_CODE=1 was used to simplification: I want tiny code that can read also in assembler code. – Igor Jul 18 '17 at 13:22
  • Sorry,I have no authority to add comments under other issues yet. :-( – SAng Jul 18 '17 at 16:48