Reputation: 2887
I have many legacy C libraries used for numerical analysis and scientific computing (e.g. simulation) that I want to use in a web application I am building (so far I have only been using Javascript to make a user interface). What options do I have in doing this on the client side and/or the server side? I heard about using native client with chrome, but I dislike that the client has to turn on the native client flag to do this.
Upvotes: 4
Views: 1672
Reputation: 169713
Another possibility would be to use the webserver of your choice to transmit ordinary files and use a custom webserver (which wouldn't need to support the full HTTP spec) wired up to your C code to communicate with client-side Javascript.
Two minimal webservers you could use as base are libuv-webserver and nweb.
Upvotes: 0
Reputation: 4998
On Server Side:
To begin with CGI (Common Gateway Interface) is the most basic method to be able to use native C libraries in a web application - wherein you delegate an executable (say written in C) to generate the sever side web content.
But CGI is very primitive and inefficient. Each command can result in creation of a new Process
on the server. Thus here are other viable alternates:
Refer: http://en.wikipedia.org/wiki/Common_Gateway_Interface#Alternatives
On Client Side:
Good News & Bad News:
You can use PNaCl (Portable Native Client) in chrome. It will be turned on by default.
BUT the first public release is expected in late 2013.Look for PNaCl
Upvotes: 4
Reputation: 1
It sounds like you're best off to represent your legacy C library methods as a kind of (WEB) service at the server side. A raw CGI application seems to be a pretty low level point for this approach, but is generally right. There are C/C++ frameworks available to create webservice servers, and client side libraries that support webservice access and data representation. For the server side you could use gSoap for example.
Upvotes: 0
Reputation: 51910
For doing it client-side, you can use Emscripten. However, this will most probably require some refactoring of your existing code to fit JavaScript's asynchronous main loop requirement.
Note that Emscripten isn't a proof of concept or something like that. It is very powerful and already used to port complex code to the web. You can take a look at the demos (listed in the above URL) to see what can be done with it.
Upvotes: 0
Reputation: 1786
You can't do much on the client side - there's no way you can expect the client to have these libraries, and no safe way to download and run them.
The simplest way is to write your server side any way you want, and access them through a web interface. Many languages customarily used for server side scripting can access native C libraries, or you can even write ordinary C applications and run them as scripting agents.
In the "really exotic" category, it is possible to run what starts as C code in the client if you embed it in a sufficiently protected environment. For example, see the description of how sqlite (a C database application) was made into a 100% pure java application by embedding a mips simulator written in java.
http://blog.benad.me/2008/1/22/nestedvm-compile-almost-anything-to-java.html
Upvotes: 1
Reputation: 25725
Looked at Wt
yet? Its pretty neat.
Also you have options to code in cgi(ugly).
Although not C, its written in C++. If you can ignore that part: Wt at your service
Upvotes: 0