I am in the process of building an iPhone app with a RoR 3 web service on the back end. The app is a fairly simple peer-to-peer game. I would really appreciate it if someone could share some pointers and tips on how to best divide the operations between the web service and locally on the iPhone.
For example, chess or backgammon, is the current state of the game being constantly saved and retrieved from the server? or is it stored locally on the iPhones of the players?
Thanks!
This will vary wildly depending on how you want to program the application and what your needs are. You could constantly save and retrieve game state from the server, you could synchronize game state at certain intervals determined by game play, or you could run mostly local. It all depends on your requirements. In general cell networks should be considered slow and unreliable (even though this isn't always true). Keeping data transfer to the minimum required to accomplish your goals makes your app feel more responsive and users happier (especially those in poor coverage areas and those who do not have unlimited data plans).
That depends on whether it's a game against another player or against a computer opponent. If it's against another player, then the state would be updated on and retrieved from the server. If it's against a built-in AI, there would be no reason to send that state to the server, unless your AI is inside your webservice instead of including it in the actual application. It's really a design decision based on what you're trying to accomplish. Generally I would recommend keeping as much as possible local to the app, unless there's a reason to do it on the server, but if there's any competitive aspect to your game, you definitely want to keep control of any calculations on your server. Keep in mind that someone can always try to decompile your application or call your webservices directly passing in false data.
Related
If I have both a web interface and a iOS application, what techniques could I use to make sure the data is sychronized between the two?
I'm looking for something that isn't overly complicated, and might not be a solution that works 100% of the time, but something reasonable.
So the scenerio is, someone uses the web interface while their iphone app is open, and say ads some data. Say this is a grocery list application, and they added 'bananas' to a list.
Now the iphone is not in synch with the changes made on the web interface.
What should/could i do in this case?
Update
Data will be stored in mysql, and ideally some will be cached locally on the iphone.
What you are describing here is a classic synchronisation problem between a mobile device and web service.
On a high level, a classic solution would be to poll for data every x seconds on your mobile device to your web service to see if there are any updates (where you base 'x' on the level of synchronization you need taking into consideration that lower values put more strain on data transfer and thus require more battery power). In order to submit changes from the mobile device to your webservice, you could require that a data connection be available so that when data is entered, it is instantly submitted to your webservice or you could queue it so when a data connection is available, it batch sends the requests to the webservice and the webservice handles conflicting data based on timestamps or some other metric.
I've been looking into the various options for implementing multiplayer (internet) in iPhone games. Game Center, OpenFeint etc are obviously very good, stable and feature-rich. But I can't help thinking my needs are a lot simpler than what they provide.
If I wanted to put together a simple 2d tank game, could I not just..
setup a mysql server on the web, with some get/set php scripts to actas 'web services'.
when you open the game, a call is made to the server, to log that you're 'available'.
when you select Play, a call is made to retrieve a list of 'available' IP's.
you select an opponent, remote IP is stored locally.
game starts, UDP handles the data between your IP and your opponent's IP.
..or would that never work? apologies, I'm very much a n00b at gaming/networking dev!
thanks in advance!
In addition to the complexities that dtuckernet points out, there are few other things to consider:
You need to think about the cost of running and supporting the web server. Can you maintain the same or better uptime than Apple and OpenFeint?
GameCentre promotes games that support it. The App Store adds an icon, and Game Centre itself lists games that your friends own. Don't underestimate the effect of free advertising!
Even if the code it easy (which I suspect isn't true), why take the risk of developing your own when there is well-tested code available for free?
Incidentally, depending on your requirements, you may want to use a hybrid approach. For example, Game Centre has a maximum of four players per game when Apple hosts it. You can find players using GC and then run the games itself on your own server.
That would certainly work, but implementing this can be a bit harder than it seems initially. You have to handle things like NAT/Firewall traversal and if you are using UDP you need to implement some type of a heartbeat to ensure you know when devices have disconnected (and handle it accordingly).
In most all cases, you would be better off working with a solution that already has these problems solved.
I have been searching and googling different ways to build a central scoring server for a golf tournament but have not found any dead set answers on how I can do this. What I'm looking for is some advice on how I should implement this. I do have a background in programming in Objective-C as I have created a couple of iPhone apps and I'm not afraid of trying and learning new things. I will explain what I envision and if I could get some suggestions on how to start, that would be great.
a. My golf tournament would have about 80 people playing in it.
b. I would have 5 volunteers with iPhones stationed around the golf course to collect scores from the players as they finish a couple of holes.
c. The volunteer would enter the scores into an app on the iPhone. The app would then send the scores to the central scoring server to update a giant leader board at the clubhouse.
My questions are what kind of database should I use? I'll need something that is very user friendly as I'll need to be able to make quick changes to the database on the fly if required. The iPhones will not share the same network as the central server as they would most likely be on 3G out on the golf course. For now, the iPhone app that is sending scores to the server, will not be in the app store as I will build the app through an ad Hoc profile.
Any help, suggestions or advice would greatly be appreciated.
You would presumably need a hosted service of some sort that each instance of your iPhone app would send its data to. Typically those hosted services are implemented in other languages/technology stacks like Java, PHP, or Ruby/Rails. The server app would then persist data into a database: MySQL is a commonly used solution, but there are a lot of options with different strengths and weaknesses depending on your specific requirements.
If a hosted server application isn't somewhere you want to go, and if your requirements are simple enough, you could look into a file-based server solution. For example, you could build your iPhone app to place scores in a small file on a Dropbox folder and then write a standalone app that collects those small files and does whatever you want with the data.
Hope that helps
If you have little experience with servers, you might also consider one of the new server-in-a-can services like parse, stackmob, or kinverse. There's quite a bit involved in building/maintaining a server, especially if you need it to scale.
What is the biggest limitation of making/using webapps?
I'm thinking that when you use localstorage, offline-browsing and geo-abilities thaht you get from html5 the differences are quite small (except for games).
The great benefit from using webapps is that they are cross-platfrom compatible!
One of the biggest limitation is access to hardware. You can't access USB ports, specialized hardware you might have (printers, bardcode readers), and other stuff, and of course, you don't have access to some very important APIs that you need today to run games (DirectX, OpenGL).
But I agree: every day they are fewer reasons to not go with a WebApp instead of a Native APP.
For iOS: When using geolocation for webapp, the user will get prompt about giving location access every time, which could be annoying for the user. Native app, only the first time.
The UI performance is also not as smooth as native. Scrolling in webview has a "slower" acceleration compared to native view scrolling.
Performance is one major difference. I see from around 20X to over 200X speed improvements when converting from Javascript to compiled C/Objective C code. One can also do real-time audio and video processing in native code, as well as low-level networking, etc.
One interesting limitation (HTML5-wise) I see is from a point of intellectual property. Since a lot of code (raw JavaScript + HTML) is exposed to the user, you have to carefully decide which components will be "open" to end users. Not aware of any standard way to lock or hide your IP once it leaves your server.
Webapps are great for reaching multiple hardware devices, you can update your app a lot faster, thus feedback is quicker. However, your users will require an always-on internet connection to use your webapp, that's probably the biggest negative about them in comparison to a native (offline) app.
I'm working on a game where really the only game part is (at least right now) that the user can unlock achievements as she does various things throughout the game. I have a database that can keep track of certain user actions and record how many times a user does something but I'm having trouble figuring out the best way to architect the app so that I have to do the least amount of work. Kind of suck with the timing because gamecenter is not ready and it seems like openfeint is changing gears, but maybe I'm wrong. I'd prefer to do everything "in house" if it is not too ridiculous. looking for suggestions.
One of the parts I'm having the most trouble figuring out is how to manage the state of all the achievements. NSuserdefaults vs. core data vs. a flat data file.
Also is there anyway to send a notification if a core data field reaches a certain amount?
Thanks,
Nick
Are you keeping the achievements on the device only, or also on the server? On the device, there is no reason not to use Core Data.
Using Core Data, you could use KVO on your model properties to monitor when certain values reach a new achievements.