0

This question must be really basic, but if you have any pointers I would really appreciate any help!

I have a Windows development project in Visual C++, and would like to send binary data (images mostly, but also other stuff) to an iPhone app over the Internet.

What is the simplest way you know how to do this? Should I use HTTP and NSUrlConnection on the iPhone, and some framework library (which?) to set up a web server inside my Visual C++ application? Or do I need to setup a proper web server like Apache (and how do I have my C++ application communicate with it then??)

So you see I am totally clueless about web technologies... if you think there is no helping me I'd appreciate book recommendations as well :)

Thanks a lot and cheers

User97693321
  • 3,336
  • 7
  • 45
  • 69
Paul
  • 93
  • 4
  • do you have a single C++ application that communicates with all iphone apps in the same time? or each iphone app user needs to use his own C++ application to communicate with his own iphone app? – talkol Dec 06 '11 at 17:33
  • In this first step there is only one iPhone and one C++ application: in the future the C++ app may serve many iPhones, but for that I clearly need to learn more about server technology... for now it's just to understand the basics. – Paul Dec 07 '11 at 11:05
  • I'm thinking about the future so we can design properly from the start. If I understand correctly, your C++ app will serve all the iphone apps, so it's basically a server, right? can the iphones operate without it? – talkol Dec 07 '11 at 18:32
  • True, it will act as a server, to be deployed either on premises or maybe in a cloud environment. The client iPhone(s) will ask for updates on data, to which the C++ app responds with computation. As soon as the computation is finished, the client must be informed (or it polls?) and pull the updated data from the server. – Paul Dec 07 '11 at 19:45
  • another important question.. can we assume the c++ app is either located in the same wifi network as the iphone app, or assume that the c++ app is running on an internet server with a well-known domain name / static IP address? or you have no idea where the users will run the c++ app – talkol Dec 07 '11 at 20:28
  • Since I'm mostly learning as I go at the moment I'd start with WiFi, but later it will for sure be running on an internet server. – Paul Dec 08 '11 at 06:25
  • Another option then worth mentioning, is having a direct data connection (socket) between your c++ app and the iphone app. I don't recommend it because your c++ app will have to implement the full server logic which isn't trivial to do. But that's how iphone apps like Air Video and Mobile Mouse work (usually only within your home network / LAN over Wifi) – talkol Dec 08 '11 at 09:07
  • Okay: I don't think I'll start that way then... – Paul Dec 08 '11 at 11:46

3 Answers3

1

Another idea can be to use some cloud storage service like DropBox. This service allows you to save files and access them using HTTP. DropBox is also free if you only need 2GB.

They have API for uploading/downloading files for several platforms here: http://www.dropbox.com/developers/reference/sdk

Unfortunately, they do not have an API in C++. But since DropBox is just based on HTTP, you should be able to use libcurl or any other HTTP library for this. This guy ran into some difficulties Using libcurl to upload files to DropBox (without answer though, but shouldn't be too hard to overcome)

Community
  • 1
  • 1
talkol
  • 12,564
  • 11
  • 54
  • 64
  • So in this model the C++ app would generate data, send them to DropBox via HTTP, and have the iPhone access it via HTTP as well. Neat! I guess there's a bit of a roundtrip time there, but to get started this sounds like an option. Thanks for the pointer to libcurl! – Paul Dec 07 '11 at 11:10
  • This is very similar to the other answer, just saves you some work on implementing the server (by using DropBox) – talkol Dec 07 '11 at 18:33
0

Not sure a web server in your C++ application is the best idea. I would implement a simple external web server in php/java/choose your poison. I would put the web server in some hosting service on a domain I would purchase. And then of course use HTTP to manage the communication between the two. The C++ application would upload images via HTTP to the web server, and the iphone app would download them via HTTP.

Also, if you don't want to purchase a hosting service / domain, take a look at services like Google AppEngine which is free as long as you don't overuse it.

Check this question for making HTTP requests from C++: How do you make a HTTP request with C++?

Community
  • 1
  • 1
talkol
  • 12,564
  • 11
  • 54
  • 64
  • I see, this is already very helpful. Would it be easier to setup a local Apache server for testing? (Never done this though.) – Paul Dec 06 '11 at 15:49
  • If you skip the cloud solutions like Google AppEngine, and decide on implementing a php server in some hosting, it may be easier to install WAMP on your computer and access the web server as http://localhost instead of the domain name you'll have – talkol Dec 06 '11 at 15:57
  • I was simply thinking about installing WAMP (needed to look that up :) on my machine and accessing it via local WLAN. The simplest I can think of would be to have the C++ app store its images to some folder the HTTP server can access, and have the client read from it. Not sure what's a good way for communicating changes to the client: In the simplest case I could poll some small text file regularly... – Paul Dec 07 '11 at 11:09
  • Sounds right. Except you probably will poll a simple DB regularly instead of a text file :) Here is a Java-PHP example of achieving the file upload bit - http://stackoverflow.com/questions/1314249/upload-and-post-file-to-php-page – talkol Dec 07 '11 at 18:36
  • I see! So I either replace or HTTP upload the updated file, and then modify the web server DB with something like a time stamp entry? I know Apache can use mysql in the backend, but how do you modify this from C++? - Sorry for the probably pretty basic questions, and thanks a lot for your help! – Paul Dec 07 '11 at 19:51
  • Apache+PHP+MySql is a combo that works well together (that's what's WAMP is all about and that's what you get in most hosting companies). From C++ you will send an HTTP command to the server, the server will execute some php code on this command and will alter the DB accordingly – talkol Dec 07 '11 at 20:30
  • Okay! I don't know yet how these things work in detail but I have now enough pointers to go ahead. I should learn about PHP/mysql then. Thanks a lot again! – Paul Dec 08 '11 at 06:27
  • If you have some experience with other languages such as C# (asp.net) or Java, keep in mind that there are server-side technologies that use them instead of php, although php is definitely the most common and popular – talkol Dec 08 '11 at 09:04
0

This should get you started on writing a PHP web service with a mysql DB and having an iOS app accessing it: http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app

this is about half the fun, the other half is basically doing the same thing with c++ (with libcurl or something similar)

talkol
  • 12,564
  • 11
  • 54
  • 64
  • Ah this is right on spot. I was looking (unsuccessfully) for some tutorial like this one. – Paul Dec 08 '11 at 06:29
  • One small comment regarding this tutorial.. I've noticed he does most of the DB creation manually using raw SQL commands. You may feel more comfortable creating and managing your DB using a user-friendly tool like phpmyadmin. It comes with the default WAMP installation and it's very intuitive + almost all hosting companies will also have it integrated (inside cpanel or something similar) – talkol Dec 08 '11 at 09:01