How do i use C++ with Flex? - c++

How can i outsource performance critical stuff to C++.
Is there any example ?

If you're talking about Flex on AIR platform (basically out of browser application), there's a way to interact with native code on the same machine.
You may want to check this out (official doc from Adobe) : http://www.adobe.com/devnet/air/ajax/quickstart/interacting_with_native_process_print.html
If you're talking about flex in the browser, then I would agree with Dmitry, you can use many different things:
- Web Services
- HTTP Request/Response
- RPC calls
- Or even make your own real-time socket (in some cases can be the most performant way to do this)
Now, that would require a C++ Server, listening to those calls, doing the stuff and then replying. => Meaning you need networking.

Now this is somewhat confusing based on tags that you chose. flex and bison are used to create compilers, and related tools.
If you are using Adobe flex then you would generally get your data from a webservice. There are toolkits that can help you create these webservices with C++ like gSOAP http://www.cs.fsu.edu/~engelen/soap.html.

Related

Web Services using C++

I am building a server-client application that involves heavy signal processing (e.g. FFT). I have a working application written in C++/Qt, where everything (signal processing and other calculations) is done in client and server just sends raw data. Now I feel it would be easier to implement these features on the server. So, that maintenance becomes easier.
As I am doing signal processing, I think I should stick to C++ for performance. But I am open to new ideas.
Constraints:
I need type checking so javascript is out of discussion.
Scaling includes adding more server and each server will have at the max
10-12 users. So, Hardware cost is important. I cannot use x number of
i7 processors.
No option of using cloud services.
So, right now my question is as follows:
How can I create web services using C++ for Linux server? (Although cross platform is not important, I would appreciate if I can achieve it.)
EDIT [02:09:2015]
Right now, I think the choice is between poco and C++ Rest SDK. I feel I should go for C++ Rest SDK. Mainly because it has only those features that I need. And Also it is supported by microsoft and uses boost internally. So, I feel in future, this might be well integreated with standard.
You could use cross-platform Poco library to implement HTTP server, it is really straightforward with this framework, and they have a lot of examples. You can also use JSON serialization (like rapidjson library) to implement REST service on top of HTTP - this way your Web service will be accesable by most of the modern Web frameworks.
You might want to take a look at the C++ Rest SDK, an open source, cross platform API from Microsoft.
Like #nogard suggested, I also recommend POCO for now. It's the most serious and feature-full solution. Given you mentioned Qt, I suggest you to take a look at Tufão.
EDIT:
I forgot to mention one comparison of mine on the C++ HTTP server frameworks.
If you directly handle HTTP requests, you might loose the functionality what Web Servers does well what it was build to do. I had a similar issue, what I did was wrap up my Qt c++ code inside a PHP extension. In your case you can do the same. Wrap your logic inside what ever technology you are about to use, doesn't matter it's PHP, net , Java or anything else.

Link C++ library to html front end

I do computational research with a C++/CUDA library that does intensive number crunching. Recently I was thinking to set up a little showcase of my library on my webpage where people could work interactively with the library and see the results (plots, animations, etc.) in real time.
I have very limited html and website creating expertise. Are there libraries out there to link the html front-end to the C++/CUDA back-end? I'm developing in Linux environment but obviously I'd like my webpage to be accessed by anyone independent of their OS and/or browser.
So after a little bit of research I found the Wt library which is written in C++ and used for webpage development. Based on the information on their homepage, it seems to be exactly what I'm looking for:
Typical use scenarios:
High performance, complex web applications which are fully personalized (and thus cannot benefit from caching), fully Ajax enabled and at the same time entirely accessible and Search Engine Optimized.
Web-based GUIs for embedded systems benefit from the low footprint of a C++ web application server.
Web-based GUIs that require integration with (existing) C++ libraries, for example for scientific or engineering applications, or existing C++ desktop applications
I did something like this. To do this, I used a simple library I wrote called jrb_node at https://github.com/kennethho/jrb_node
There are other libraries like cppnetlib http://cpp-netlib.org/
Basically you make a small http server that based on the request will perform some computation and return the results as an http response. You can then combine that with javascript and Ajax if you want to make it more interactive.
An alternative to consider is to use WebCL. CUDA is pretty similar to OpenCL and it should be pretty easy to convert your code to the latter. If you have other C++ code, that might be a bit of problem though.
Do you want to run CUDA on server (e.g. the users will input the parameters, push a button and your server will do number crunching) or on client (e.g. it will be user GPU that does computations)?
For server-side you should be able to use pretty much any server technology - PHP, JSP, etc. They all provide a way to integrate to "native code".
For client-side you will not be able to do with just HTML - you need to use some "fat client" technology - e.g. ActiveX, Java applet. I do not know if Silverlight or Flash have access to native code. IMHO, you might as well just write a Qt application and put a download link on your site.

Program interacting with web

How or what do I need to know programming wise in order to interact with the web using c++. For instance i want to wrote a program that automatically sends invites to players on yahoo chess. How would i go about doing this?
You'll need to understand the basics of TCP/IP and HTTP, possibly UDP, and the protocols involved with Yahoo's chess systems or posses a tool to work around them (A brief search leads me to believe there are few if any). You'll probably need a network API, I'd suggest looking at:
QtNetwork Module
Boost.Asio
Where Qt is easy to use, Asio is more powerful, and more 'C++' in nature. Qt has some nice webkit components, and I've used it to build a small web server, which was a lot of fun. You can accomplish quite a lot with it.
This page says they've added a captcha system to prevent certain people from interacting with their systems. I'm not familiar with Yahoo games and what the result of this has on what you'd want to do, however it suggests to me they'd rather you didn't write code to interact with their systems.
For this you need to use network APIs and use server side script like PHP/ASP to communicate with the web and C using message queue.

Creating gui binding for c++ and YUI

I am planning to use yui or jquery ui as front end for native c++ applications. I found no bindings present for this purpose. Will it be feasible/possible to do this ? If it is so, then how shall i proceed? please suggest advice.thanks
#rwik - I can see your point and desire to do what you intend and I would presume it to be a wise move to be making at this point in time considering the vast facilities browsers bring to the table as well as other aspects... I know we are in September now and I have come across this pretty late, but this is also for others who have a similar problem...
As far as I know, descending from JavaScript in to C++ is pretty murky, mostly due to the heterogenous nature of Javascript engines [Rhino, Tracemonkey, Spidermonkey, V8, Caracan,Charka, etc] employed by different browsers. But there are indeed ways to do this - depending on how dirty you want to get your hands and, indeed, on your abilities...
If you were to go with Google as a browser, you should take a look at projects such as cproxyv8 - http://code.google.com/p/cproxyv8/ or v8-juice - http://code.google.com/p/v8-juice/ which both offer interesting facilities...
My preference however is with Mozilla - simply because of XML User-Interface Language (XUL) which, if you do not know, allows you to speedily create your own user interfaces by giving direct access to its layout engine. I.e., you can even do away with the browser look and have your own independent layout while still having all browser facilities at your disposal.
With respect to C++/Javascript interaction - projects should exist for all alternatives - it pays to check.
I wish you good luck if you haven't already solved this problem.
I'd recommend QT instead.
However since native C++ has nothing to do with GUI I'm going to assume you are making a library in C++. However Yui is basically just JavaScript as is jQuery. So if you're asking can a web page or script be a C++ application the answer is not really.
What you could do is create a web service which uses your C++ library and exposes an interface for your web based application to call it indirectly.
One way to accomplish this is to embed WebKit into your application and provide your custom C++ functionality via a plugin. Both the WebKit framework on OSX and the Chromium Embedded Framework on Windows allow this style of application development. This allows you to write a UI using local Javascript/HTML files without the need for a webserver.
There are no direct bindings in JQuery and YUI because these libraries run in a web browser. Thus unless you’re planning to write your own browser plugins, the integration with the C++ will happen at the webserver that serves the data to the browser.
You could feed the data from your C++ code directly into JQuery/YUI by building web services directly in C++. But you might want to build a web application that will be serving your JQuery/YUI pages and that act as user interface controller (like in the MVC pattern). Web application languages like Java, PHP, etc. all have ways to call native code. Java has JNDI and in PHP you build extensions that link to C++ code.

What works for web dev in C++

I want to create a web application that runs with very little RAM and I think C++ can help me achieve that.
Now, many people say C++ is unsuited for web development because:
there is no easy string manipulation
is an unsafe language (overflows, etc)
long change / build / test cycles
etc.
But I'm sure the C++ community have found ways to alleviate all those (maybe not the compile time) however since I'm not a regular so it is hard for me to put a value on what I find in Google.
So I'm asking for some guidance. I would appreciate if you share what works, what tools/libs are current and alive. What strategies can help with web dev in C++? FastCGI or embedded server (Asio / POCO / Pion / etc.)? How do you address security concerns?
Thanks a lot for any help
Have you looked at http://www.tntnet.org/. They have created a... well let me cut and paste from their website:
Tntnet is a modular, multithreaded,
high performance webapplicationserver
for C++. To create webapplications
Tntnet has a template-language called
ecpp similar to php, jsp or mason,
where you can embed c++-code inside a
html-page to generate active content.
The ecpp-files are precompiled to
c++-classes called components and
compiled and linked into a shared
library. This process is done at
compiletime.
I've used it and it has quite a small overhead plus it has screamingly fast dynamic page generation. Makes PHP, Ruby etc snails in comparison because with tntnet you are running compiled C/C++ code.
There's the Wt Project. It uses a paradigm similar to Qt's signals/slots.
There is nothing wrong with trying to build a web app in C++. It's actually a lot of fun. What you need is a:
Templating system
A CGI lib
A database API wrapper, most likely, to avoid dealing with something like the low-level MySQL API
A logger
ATL Server is a library of C++ classes that allow developers to build internet based applications.
ATL Server. It's open source too! And of course there is always ISAPI. Ah, the bad old days. :)
In your other question you mention that your embedded system is openwrt. As this router firmware already comes with a embedded web server (for it's administration UI), why don't you use that for you app as well?
Our web app backend is in C++ via CGI and we use Clearsilver templates along with the HDF that comes with it.
Give us some more hints about what you're trying to do.
You can write a good old-fashioned cgi program in C++ easily enough, and run it with FastCGI. We used to do that all the time.
You could write a C++ program embedding a lightweight HTTP server as well.
Both of them are much bigger PITAs than using something like perl or ruby.
So for why C++?
Update
Okay, got it. The main thing about FastCGI is that it avoids a fork-exec to run your CGI program, but it is a little bit different API. That's good, but you still have the problem of handling the HTTP stuff.
There are, however, several very lightweight HTTP servers, like Cherokee and Lighttpd. In similar situations (building web interfaces for appliances) I've seen people use one of these and run their C/C++ programs under them as a CGI. Lighttpd in particular seems to concentrate on making CGI-like stuff fast and efficient.
Another update. I just had cgicc pointed out to me: http://www.gnu.org/software/cgicc/
That might solve some problems.
You can try Cutelyst a C++11 built with Qt, with one of the best positions on TechEmpower Benchmarks.
Even though it requires Qt 5.6+ a full CMS (CMlyst) uses around 6MB of RAM while serving around 3000 requests per seconds on a single core.
And for your string manipulation issue QString is just an amazing class for that.