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).
Related
I'm building a C++ application that produces data that I want to pipe to a web browser. If I send all of the data to the server, and then out to clients, there will be too much traffic. Is there a way I can use my server to establish a direct socket connection between my C++ application and a remote browser?
I'm writing my server using node.js for what it's worth
Yes: you can embed a web server inside your C++ application. If you can poll for the data using simple HTTP GET, you can use the simple C web server library "mongoose" for example. Or you may need to use WebSockets which probably requires a fancier library in C or C++. Then your Node.js server can simply give the URL of your C++ server to the clients, who will connect to the C++ server directly.
All that being said, it's likely that Node.js can support the load, so if you haven't actually run into scaling problems, you might want to just skip this whole project.
I have a question related to HTML5 as a desktop application replacement.
At present time my company developed a WinCE application in C++ language with a GUI in C++, that receives and sends messages to the Business Logic layer via sockets (C++ Windows App).
We would like to port this SW on Linux but to realize a cross compilable SW.
The whole application run on a single embedded PC (both BL and GUI) .
About presentation layer we was investigating the HTML5 possible solution, however I have some doubts.
In fact I read that some browsers supports the feature of web sockets, but it seems that this kind of sockets aren't generic TCP/UDP sockets, but are further specialized and their implementation is provided in server side classes, like Socket.IO (Java e node.js) and Jetty (Java).
So is there someone that can provide me some feedback about how/if it is possible to use HTML5 as presentation layer and send/receive updates from/to GUI via sockets to a application running on the same host machine as the web page?
I hope this question fulfill the requirements of the stackexchange "style" and rules, I made my best to be as clear as possible.
Best regards.
Giovanni Parodi
Nothing stops you from having your frontend and backend on same host talking via WebSocket over loopback.
I assume you are unwilling to port your backend to a different language, so you will need a C++ WebSocket implementation. I haven't followed what Microsoft provides in this area, but when using Boost/ASIO, I'd recommend to look at WebSocket++.
Further, WebSocket is still relatively low-level (send message bidirectionally). So you might want something higher-level. You might want to look at WAMP (The WebSocket Application Messaging Protocol), which provides you with RPC and PubSub messaging patterns. Using this, you can plug/exchange your frontend (e.g. have a native Android) talking to same, unchanged backend - same for backend. Decoupling.
There are clients and router(read: server) implementations for various languages.
Btw: WebSocket is supported by Chrome, Firefox and IE (beginning with version 10) -- and other browsers.
I'd need to know more about the specific side-conditions and requirements to give more hints ..
Disclosure: I am original author of Autobahn, WAMP and work for Tavendo.
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.
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.
I have javascript (client - executed through node.js) and C++ (server) code running on Ubuntu (Linux) and I want this client-server to communicate with each other. Can somebody tell me how I can make C++ code work like a server or client using web socket? Basically, I want javascript code to send some data to C++ code, the C++ code will process on the data and return the result back to javascript code. I'm not sure if I this communication between javascript and C++ code can happen with out web socket. Any pointers in this direction would be of great help!
Thanks,
pats
I very recently started working on a C++ websocket library: https://github.com/szmoore/foxbox
An example of a websocket server is: https://github.com/szmoore/foxbox/blob/master/examples/wsserver.cpp
I also have an example of a JavaScript client.
Warnings: The library doesn't support TLS, is based around POSIX sockets, and is still in development and probably horribly insecure.
So, whilst shamelessly promoting my own library I will also point you at libwebsockets, a C library suggested in answer to this question: https://stackoverflow.com/questions/3916217/standalone-c-or-c-websocket-server-library?lq=1
You have several choices. I am assuming your C++ server already has a websocket server running on it but if not, get Mongoose or the non-GPL fork Civetweb. Both are tiny bits of c code you build into your C++ program to add webserver,including websockets, functionality.
In fact, civetweb comes with a websocket example.
However, you do not need a websocket, just an ordinary socket should do. You'll probably want to send the data in JSON format to makeit easy to consume by the javascript code.
I know this question was asked a LOOONG time ago, but here is a gist of my set up that allows to have a communication between my c++ and Javascript apps; if anyone stumbles on this question:
I use TCP/IP connections to set up communication between a C++ app and a Javascript (Typescript) app. ZeroMQ (0mq) library is perfect for that. On c++ side you have libs like zmqpp and on the JS side you have zeromq.js.
After the data is received in JS land, you can use Socket.IO if you would like to have that streaming data available in a browser. Generally, you would have to forward the data stream off 0mq through Socket.IO and then access it on the browser side.
Bonus: make the data format using Protobuf.
On the Javascript side you will probably want to use an XmlHttpRequest. This will cause the javascript to post an HTTP(s) request to your server. For the C++ server side, you can look at something like Pion for an embeddable HTTP server or if you want to link into a full web server like Apache, you can use Fast CGI to plug your server code into Apache.