470,643 Members | 1,229 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

Running an existing C program on a web application?

5 Nibble
I have a set of C programs for data analysis that take an input of files and display desired output via the command line.

How do I make these programs accessible in a web application without having to code them up again in a web programming language?

Can i use the existing C code?
How would i do this?

Jan 3 '21 #1
4 8002
570 Expert 512MB
Have the backend language execute em via shell providing the required input data. Then redirection of the output can be done to the web application.
Jan 4 '21 #2
2,446 Expert Mod 2GB
As dev7060 said that is one approach and probably the easiest if you are already familiar with a web-programming language that has functions that can execute code on the server.

Another is to use Web Assembly also known as WASM.

It really comes down to your existing code-base, your ability and the need for application to perform.

What is Web Assembly?
Web Assembly is a specification for a virtual machine that runs in the browser. Compared to the highly dynamic JavaScript, Web Assembly can achieve much higher performance. Contrary to popular misconception though, Web Assembly doesn't completely replace JavaScript. You will probably use the two together. Web Assembly is based on LLVM (Low Level Virtual Machine), a stack based virtual machine that compilers can target.
Why use it?
Typically, when people talk about the advantages of WebAssembly, itís from the standpoint of performance. But WebAssembly brings another advantage to the tableócode reuse. Rather than writing the same logic multiple times for each target environment (desktop, website, and others), WebAssembly lets you reuse the same code in multiple locations.
Here's a doc on dev.mozilla that helps setup a basic C++ module to Web Assembly.

The jist of it is:
Compiling C++ code into Web Assembly using ( Emscripten )
Emscriptem is a LLVM to JS compiler which results in
  • The binary wasm module code (hello.wasm)
  • A JavaScript file containing glue code to translate between the native C functions, and JavaScript/wasm (hello.js)
  • An HTML file to load, compile, and instantiate your wasm code, and display its output in the browser (hello.html)
Call the HTML file in a browser that supports Web Assembly
  • Web assembly is enabled by default in Firefox 52+ and Chrome 57+/latest Opera
  • You can also run wasm code in Firefox 47+ by enabling the javascript.options.wasm flag in about:config
  • Chrome (51+) and Opera (38+) by going to chrome://flags and enabling the Experimental WebAssembly flag.

Some intriguing points about both methods.
  • Security - because it's server code, the inputs should be strictly validated and contained to keep arbitrary from code executing on your server.
  • Server Performance - also it might have an effect on the performance of other users of your service depending on if you run as a service or execute on demand.
Web Assembly ( Client ):
  • Local performance - test it for performance on various machines before deploying it ( memory leaks etc )
  • Security - It's contained in a VM on the client browser, regardless input should be validated.
  • Feature access - The compiled WASM binaries will have access to the same features that the browser has on the client machine.

Other languages that WASM supports
  • C/C++
  • C#/.NET
  • Elixir
  • Go
  • Java
  • Python
  • Rust

Compiling a New C/C++ Module to WebAssembly
Introduction to Web Assembly with C/C++
Reusing your existing C++ codebase
Emscripten - compiler toolchain to WebAssembly, using LLVM.
Jan 4 '21 #3
212 128KB
Easy does not always equate to safe.

I think that about a few of years ago I was researching WASM as it related to security and I think (if I recall correctly) that I found at least one reason to avoid it.

Maybe. But, I think that it might be on my list of what to not use. Maybe. For some reason I seem to be avoiding using it. I do not recall if or why.

As some radio talk guy says, "I am not saying anything. Just saying."
Jan 14 '21 #4
1 Bit
data analysis that take an input of files and display desired output via the command line
Feb 12 '22 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Lothar Scholz | last post: by
2 posts views Thread by =?Utf-8?B?SmFuIExpbmRo?= | last post: by
7 posts views Thread by =?Utf-8?B?U2hpdmEgUmFtYW5p?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.