Advertisement

Communicating between C++ and php

Started by January 30, 2005 11:13 PM
2 comments, last by Motz 20 years ago
Is there a way to send data from a C++ program to a php script on a server? I'm basically trying to create an update server for this program, and I need a way to see if the program needs to be updated.
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
i dont know much about PHP, you should try googling for "PHP C (or C++) API". however for what you want to do you could always just use regular HTTP, and then just download a file off a web server like www.game.com/latest_version.txt. this text file would just contain the latest version number of the program. if this version doesnt match up to the one thats hard-coded into the program (or written to a file somewhere), then the client knows that he needs to update.

you can do HTTP using C++ relatively easy using hplus's HTTP GET library. i havent used it myself but it seems very simple and light weight.

good luck.
FTA, my 2D futuristic action MMORPG
Advertisement
Well the way PHP works is that the webserver gets an HTTP request for the php page, executes the PHP script, and sends the output back to the client. So as long as you just have the PHP script print a simple string you should just be able to form an HTTP request and send it to the server and collect the output.

kman12
A simple way to check if the game needs updating would be to put a file on the server containing the latest version number. The file could be HTTP GET'd by the game and compared to the version number of the installed version of the game. This is easiest as it only requires a static text file which can be manually updated.

If however you later decide that you want more complex communication between the game and the webserver, XML-RPC would be a more scalable way of doing things. Libraries exist for both PHP (https://sourceforge.net/projects/phpxmlrpc/) and C++ (http://xmlrpc-c.sourceforge.net/) for this purpose.

This topic is closed to new replies.

Advertisement