Two way communication using AJAX from an HTML page to a C++ application running in same server - c++

Is it possible to communicate from a web browser(Loaded an HTM page from server) to an application running in the same server using AJAX. Need to send the request from browser using a button click and update the page with responses received from one another application running in the same server machine?
I am using HTML pages to create website and not using any PHP or ASP like server side scripting. In server machine data are manipulated using a C++ application.

I think you can use any sort of Javascript functions to do that. But you might need to use jQuery or similar frameworks to make your live easier. You might need to search for "Comet Programming" to know exactly how to do 2-way communication between client and server
Updated:
Well, this kind of stuff requires you to read a lot (if you have not already known). Basically, what you need is a server that can do long-polling (or eventsource, websockets). There are many open-source ones that might help you to get started. I can list a several good ones here. There are a lot more
http://www.ape-project.org/
http://cometd.org/
http://socket.io/
http://code.google.com/p/erlycomet/
http://faye.jcoglan.com/
So after you have the comet server up and running you will need to setup the client side (probably Javascript). For those listed projects, most of them come with the client side code to interact with the server (Except for erlycomet). Therefore, you can just use the examples provided and run a quick prototype. If you want to use your raspberry pi, you can use nodejs which provide a lot of ease for dealing with real-time communication (socket.io, faye). And lately, http://www.meteor.com/

I would think of the problem this way: you want to provide a web front end to an existing c++ application. To achieve this you need to think about how your web server communicates with your c++ application. Communication between the browser and web server can be thought of as a separate problem - as you say AJAX calls can be used, or maybe have a look at websockets.
Once you have your request in the web server you need to communicate it to the C++ application (and/or visa versa). This can be done a number of ways, e.g. sockets or RPC. I found this question here which has some good advice.

Related

send array from c++ application to webApplication

i want to send one array from my Desktop application (c++) to another Web application(browser-based) which is written in javascript.
What is the standard approach to do this ?
my purpose just is to try send array through websocket to a simple web application.
i am a little familiar with node.js but i dont know is it possible to use it inside c++ application or not.
I want to send one array from my Desktop application (c++) to another Web application(browser-based) which is written in javascript. What is the standard approach to do this ?
Your question is too broad, or shows some misconceptions about desktop applications and web applications.
Be sure to understand (in details) HTTP and reason in terms of HTTP requests and responses (including those initiating a websocket connection). Remember that a websocket is above some HTTP connection.... Understand the role of HTTP cookies.
You could change your desktop application into a web application (perhaps running on http://localhost/ ...), but that requires some significant work and redesign. You probably then want to use some HTTP server library, like Wt or libonion (it supports Websockets).
Perhaps you might improve your web application to make AJAX requests (e.g. to some http://localhost:34567 ...) to you local application transformed into a specialized web sever running locally (and also using websockets, if you need that).
Perhaps you want your Desktop application to also become an HTTP client. You then need some HTTP client library (like libcurl or QtNetwork).

Cloning PyQt app in django framework

I've designed a desktop app using PyQt GUI toolkit and now I need to embed this app on my Django website. Do I need to clone it using django's own logic or is there a way to get it up on website using some interface. Coz I need this to work on my website same way it works as desktop. Do I need to find out packages in django to remake it over the web or is there way to simplify the task?
Please help.
I'm not aware of any libraries to port a PyQT desktop app to a django webapp. Django certainly does nothing to enable this one way or another. I think, you'll find that you have to rewrite it for the web. Django is a great framework and depending on the complexity of your app, it might not be too difficult. If you haven't done much with web development, there is a lot to learn!
If it seemed like common sense to you that you should be able to run a desktop app as a webapp, consider this:
Almost all web communication that you likely encounter is done via HTTP. HTTP is a protocol for passing data between servers and clients (often, browsers). What this means is that any communication that takes place must be resolved into discrete chunks. Consider an example flow:
You go to google in your browser.
Your browser then hits a DNS server (or cache) that resolves the name google.com to some IP address.
Cool, now your browser makes a request to that IP address and says "get me some stuff".
Google decides to send you back a minimal amount of HTML and lots of minified JavaScript in the page.
Your browser realizes that there are some image links in the HTML and so it makes additional requests to google to get each of the images so that it can display them.
Now all the content is loaded on your browser so it starts to execute the JavaScript code, and that code needs some more data from google so it starts sending requests to google too.
This is just a small example of how fundamentally different a web application operates than how a desktop application does. On a desktop app you have the added convenience that any operation doesn't need to be "packaged up" and sent, then have an action taken, etc (unless you're using a messaging architecture, but that's relatively uncommon outside of enterprise apps).

Calling c/c++ library from webserver

I am pretty new to web programming.I am developing a HTML5 based user interface which is supposed to use a middle ware written in C/C++.How can I do this?
I do not want to use any browser specific feature/library to communicate with the middle ware. Can we do the same at the server side and then send back the information to the browser? If so how can I achieve this communication with the middle ware at the server side?
Thanks in advance for the reply.
Note : I am planning to use Tomcat as the server in loop back.
As suggested above, you could use CGI (e.g., perl scripts) as a middle-man between the Tomcat server and your C++ middleware. What I also think might work well, and am planning on using myself in the near future, is to use boost::asio, and take the example HTTP server and modify it to use your middleware. You could then communicate between the Tomcat server and the C++ server using AJAX with JSON.
There is also something called pion server http://www.pion.org/projects/pion-network-library
It allows you to write the entire server in your own C++, with most of the common tasks abstracted away.
The Wt "web toolkit" library (pronounced "witty") may be of interest. Essentially all web-aspects are taken care of this, so absolutely no middleware. Here is an intro, quoting from the website:
The API is widget-centric and uses well-tested patterns of desktop GUI
development tailored to the web. To the developer, it offers
abstraction of web-specific implementation details, including
client-server protocols, event handling, graphics support, graceful
degradation (or progressive enhancement), and URL handling.
Unlike many page-based frameworks, Wt was designed for creating
stateful applications that are at the same time highly interactive
(leveraging techinques such as WebSockets and Ajax to their fullest)
and accessible (supporting plain HTML browsers), using automatic
graceful degradation or progressive enhancement. Things that are
natural and simple with Wt would require an impractical amount of
effort otherwise: switching widgets using animations, while being
perfectly indexed by search robots with clean URLs, or having a
persistent chat widget open throughout, that even works in legacy
browsers like Microsoft Internet Explorer 6.
It can run with its own web server (based on a Boost component) or be linked against standard web server libraries.
I wrote a short blog post about how to integrate it with another C++ component I wrote (RInside, which permits to embed R inside C++ apps) and by joining the two, I had a simple 'webapp' exporting R functionality to the web.
You can further enhance it via Javascript but that is something I have not looked into in any detail.

REST Server, Delphi and Web Services - Advice needed

I am looking on advice on how best to approach a new project I need to develop. From the outset I must add, I have 0 experience with Web development on any level.
What I need to do is provide a web interface through the browser which will communicate with a server back end. The data retrieved will be sourced from either a DB or from another source - external device which the server itself will communicate with via IP. The data retrieved from the external device will always be a string format of n length (non unicode) and the DB data will mostly be strings and numbers with the odd blob thrown in (storing a picture). The communication will always go from the Client (web browser) to the Server. I don't believe that the server would need to instigate the comms.
I have Delphi XE, so started looking at using a REST server for communication and I think that seems to be OK. However, from what I can see, I need to create HTML web pages to "render" the data on the web browser. Is that true? Can I use the IW components with a REST server? If so, I'm not sure how to get the data to/from the browser UI. Am I better of investigating Ruby on Rails perhaps? From what I read on a different thread in here, it's based on MVC and some other areas which I feel, design wise, would fit how I would create the application (I was planning on creating the app based on the MVP or similar design pattern).
I think REST makes the most sense, so if the IW components can't be used, are there any 3rd party products I can use which would let me design "pretty" UI html. Given I don't know java script, would that be a stumbling block with REST too.
Thanks and hopefully I have provided enough information.
Thanks
Jason
Will a human being be responsible for typing the data retrieved from your external device into a web page?
If so, and you have no web development experience, Intraweb is definitely the way to go for Delphi programmers wanting to build a web application without learning new skills. For additional components to create a prettier UI I suggest using TMS Software's Intraweb Component Pack Pro.
If you don't need a human being to manually type in this data then you don't need Intraweb at all. Instead you would write a client application which presumably interrogated your external device for the data and then transmitted it to the REST server. Look at the documentation you've used to build your REST server and it should have a section on how to build a REST client.
You can build an ISAPI module with delphi that does the job, or include a HTTP server right into you executable with Indy, ICS or Synapse.
ISAPI will give you the freedom to choose Apache or IIS and give you all their power this way. Embeded HTTP server will give you a nice small application in which you control all ascpects of how it works.
Yes go with REST as it is simple and clean. All you need is to think and design the API (functions that your server will support). You can bind the APIs to the URL schema thus using the REST principle. I would do it simply like this.
A client makes a request. You show some form of GUI (load or render a HTML page with possible javascript)
User makes an action, you call appropriate API (or the user does it directly).
Show the user some result
Just guide the user process through a series of API calls until the result is made
You can use plain HTML and then add javascript if needed (jquery) or you can use ExtJS from Sencha which makes building a nice GUI a lot easier and is very well structured.
I would not use any "WYSIWYG" web tools. Plain old HTML written by your favorite editor is still the king in my opinion.

Using C++/Qt4 application as backend for web application

for one of my applications I'd like to provide a minimal web interface. This core application is written in C++ and uses Qt4 as a framework. Since I'm also using some libraries I wrote to calculate some things and do some complex data management, I'd like to use this existing code as a backend to the web interface.
Idea 1: Using an embedded web server
The first thing I tried (and which worked to some degree) was using an embedded web server (mongoose). As you can imagine, it is just a very thin library and you have to implement a lot of things yourself (like session management, cookies, etc.).
Idea 2: Using a normal web server and adding a fcgi/cgi/scgi backend to my application
The next thing that came to my head was using a mature but compact web server (for instance, lighttpd) and simple provide a fcgi/scgi/cgi backend to it. I could write the web application using a good framework, like Pylons, PHP, or RoR, (...) and simply have an URL prefix, like /a/... which allows me to directly talk to the backend.
I tried to implement the libfcgi into my application, but it looks messier than needed (for instance you'd have to implement your own TCP/IP sockets to pass on data between your app and the web server and tunnel it through the FCGI library, meh)
Idea 3: Creating a command line version of my application which does the most basic things and use a normal web server and framework to do the rest
This is the third idea that came to my head. It is basically about creating a web application using a traditional way (PHP, RoR, etc.) and using a command line version of my application to process data and return it when needed.
I've got some experience with creating web applications, but I never had to do something like this, so I'd like to hear some ideas or suggestions. I'd like to use JavaScript on the browsers (AJAX, that is) and pass some JSON constructs between web browser and server to make the user experience a bit smoother.
So what are your suggestions, ideas on this? I don't want to re-invent the wheel, honestly.
I would never expose a custom written application to the net as front-end, for that servers like apache or lighthttp are build. They give you some serious security out of the box.
As for interaction of your app with that webserver, it depends a bit on the load and what kind of experience you have with writing software in PHP, python or other languages supported by your web server (via interpreter of course).
A slight load, and a command line tool accessed from PHP might do perfectly well.
A more heavy load and you might wish to implement a simple (SOAP?) server with Qt and access that from a python (or php) script.
That way you don't need to do layout in you app, and you also don't need to implement security all that much.
I'm currently researching a similar situation (custom web app backend using Qt), and the least bad option is FastCGI. Found something you might be interested in. Not production ready without some serious testing, but this might be a good starting point for Qt - FastCGI interop: FastCGIQt
I've used the FastCGI Protocol Driver library for a similar project (also a Qt application), the download link is at the end of that page [Libfastcgi]. Integration with the application turned out actually comparatively easy. Lighttpd + mod_fastcgi was used as web server. Can't say anything about FastCGIQt, though.
You Wt works well to provide a web interface to Qt based applications. Both have a similar programming style, and there's an example that demonstrates the integration with Qt.
Here is example of embedded QML-server: https://github.com/ncp1402/ql-server