Getting a webpage to link to a C ++ application

I want the web page to send a message to the C ++ application, but this requires some form of connection from C ++ to the web server and from the web server to the client.

One way, I thought it would have a MySQL database that stores the message, and the C ++ application uses libCURL to request the web server via php script for any new messages. He would have to interrogate him every second or so, which would be a little empty. In addition, whenever you want to send a message from a web page, you will have to send the form back to the web server, which will be slow.

I also looked at HTML5 websites, believing that it is possible to create a TCP connection between the client and the C ++ application, but I don’t think they work. Are web sites designed to route messages between two HTML5 applications through a server, or could theoretically use an HTML5 application to communicate directly with the server (maybe run a php script or send a regular TCP packet)?

Any suggestions on how I could achieve this would be welcome.

Thanks.

+4
source share
3 answers

If you want to make remote procedure calls from your site, I would recommend looking at SOAP. SOAP works fine with PHP , and with gSOAP you can easily insert the server interface into your C ++ application or vice versa if necessary.

If you have only very simple messages for the application, your database idea will also work, but your application will need to continue to check for a new message (which means a lot of unnecessary traffic if your database is not on the same computer as your application), and you will have to deal with these checks yourself, come up with models, etc.

SOAP, on the other hand, sends your data directly to your server application and implicitly processes all unpleasant things, such as type safety or serialization.

You can find a lot of documentation and examples, carefully explaining how SOAP is determined and how it works from the World Wide Web Consortium . There are also various examples of how to configure your SOAP server in C ++ in the gSOAP User Guide .

+3
source

If you are writing a program in C ++, you can simply write it to use CGI so that your web server runs your C ++ program as a "script" to process the corresponding HTTP requests, and you will directly output http from your C ++ programs.

http://en.wikipedia.org/wiki/Common_Gateway_Interface

+2
source

It is not very simple. You should look at Google's solution:

A cloud-based messaging system used to send messages to Android devices.

What you do is called Push. Here is a video of this from Google IO.

Think of your C ++ application as an Android device.

Your C ++ application will establish a connection to the server through some tcp / ip port for the service being created, which simply waits for connections. Your application would tell the server the identifier of the user running the application, or if it was a multicast, the application simply waited until the device gave it a message.

Your web server can use process communication, namedpipes, named mutexes, etc. to lower your service to send a message to all open TCP / IP connections.

+1
source

Source: https://habr.com/ru/post/1397132/


All Articles