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.
Related
I've made an iOS game that works over both Bluetooth and bonjour. It works great both ways, but I'd really like it if players could play with eachother with any Internet connection, be it edge, 3G, or different wi-fi addresses.
The catch: I don't have the resources or knowledge to set up dedicated servers or anything like that. It seems that surely GameKit has something in it that will let me do this, but despite spending dozens of hours over the last week figuring out how to use it, I've found nothing.
So, does anyone have ideas for solutions? My game is just one on one, if that makes it any easier.
Why don't go through the Game Center with GameKit?
Apple provides all the infrastructure to play all around the world via their servers (in 3G or Wifi). With the Game Center you can play up to 4 players (so in your case there is no problem), it's free, you don't have to manage any server, there is a mechanism of invitation between friends, and many more.
The logic of your game stay in the client side, so it'll be same design as your actual game (expect for the API I think).
You can find all information on the official documentation here.
If you want, there is a very tuto on the ray wenderlich's blog (but it uses the cocos2d framework instead of the CocoaTouch).
Yep, try GameCenter with GKMatch - works really well if game doesnt need to send tons of data. If you make additional layer between your app and GKMatch and GKSession, you can use both transparently (so your game supports local AND global multiplayer). Tested, it works
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.
I'm trying to figure out if game center is the right tool for me. Here's my situation:
I'm building an app which allows users to create their own musical compositions. I plan to make the compositions exportable and loadable via text file (xml or json format, probably). I'd like to allow users to share their compositions with friends. It seems to me that game kit is the default social network for iOS, so it seems worth looking at. However, the social aspect of game kit seems to be designed mainly for real-time, simultaneous play. Is there any way to share data with friends in a non-realtime way via game center? Is there even a way to send game center contacts a message?
If you look at the documentation for peer-to-peer networking in GameKit, you will probably find exactly what you are looking for, with a tiny exception. It is only for wifi/bluetooth connectivity.
The way I would go with your description is a private server that hosts the compositions. If you are familiar to Java and/or Python, I'd recommend using Google App Engine for the server. That would make the headache a little bit less.
You can use GameKit too, but as you describe it, it's more for real-time communication.
If you implement invitation handlers, you could "invite" another player to receive the composition, but if they reject you will have to retry manually at a later point.
The contents of what you sent over an open "GameKit connection" can be "anything" you like, stuffed into a NSData object, so there is no limits there.
I hope this helps you a tiny bit in the right direction, good luck!
I am asking this question as a small part of my question series regarding game programming .
Refer this question as the main one .
Now suppose I want to develop one small board game on iphone that is multiplayer . so how it will handle how many users are online and displaying them .
Suppose it is an online multiplayer casino game .
Then suppose it have to show currently playing tables and users on them .
So what can we do in iphone to do this sort of thing .
Thanks .
You're essentially asking what is referred to as 'matchmaking' in PC and console games.
The notion of displaying all currently online players or active matches is an early one in online multiplayer gaming, and I think it's seen its time. Instead, try and offer your players two options: Play with your friends or play against people of your skill level.
Showing someone a complete list of tens/hundreds or even thousands of games/players is just going to overwhelm them. People are much more comfortable knowing they're playing against people they know (and trust not to be unsportsmanlike) or at least that they're playing against someone of comparable skill level. These 2 concepts are often called 'buddy based matchmaking' (or friend lists) and 'automatch' or skill based matchmaking.
Unfortunately, from what I've seen in the GameKit framework, neither are fully supported, at least as far as playing on non LAN connections. You're going to have to either develop that yourself (and very few iPhone developers are going to have the resources to create and host it), or see if someone like OpenFeint, ngmoco (plusplus), Chillingo (Crystal) etc match your needs. OpenFeint seem to be talking about matchmaking on their site and plusplus offer buddy based challenges. The OpenFeint signup process is the easiest and you get access to their SDK right away for development without prior approval.
Now here's one final thing to consider: smaller games aren't going to have the player base to have enough concurrent players around so that everyone will always find a suitable match at any time of the day/week. Unless you have promotion and publisher backing, or a breakaway hit, picking an automatch based solution is not your best bet and shouldn't be your only mode of matchmaking. Ideally your game should allow for some turn based form of game play, so you can play asynchronously. That model has worked great for games like Words With Friends.
You need a server, you gameclient will contact it to get assigned to a partner. This is call matchmaking (google it to learn more).
I think there are OpenSource solutions (or at least frameworks) for this. But I don't know them. I know however Exit Games Neutron and Photon and I think there are free licenses for private / educational use.
used this website for the long time to find answers, now need to ask on myself! :)
I have implemented multi player for my game using GKSession and client/server approach, not using peer picker (up to 4 player allowed).
I have one big problem which I can't find solution for.
If you disconnect/reconnect server peer quickly enough, client peer will "remember" that host and will show it in the list of all available peers permanently, only turning wifi/bluetooth off resets this.
So if I do this 5 times in a row, my client will show 5 available hosts with the same name!
Anyone had experience with this? Any idea of workarounds?
I should note that requirements for my game is iPhone SDK 3.0 for Bluetooth and 3.1 for Wifi as GKSession supports both now.
I have a similar problem. In fact I event get peers listed who are not even currently playing the game. Even more so, peers who are not acting as server are listed. I am wondering if there is some behind the scenes caching going on.
I'm thinking about implementing some kind of timer with visual feedback to show the disconnect progress, ideally to prevent this situation. It seems like in general there is a bit of time delay involved with connecting/available and disconnecting/unavailable. It might be better to code the interface to take these time delays into consideration, though I'm not sure exactly how.