I’m trying to design a multiplayer android game that has a persistent virtual world. I have a server with a database that represents the current state of the world as well as some exposed web services. I have an android app that draws a particular player’s view of the world, as well as makes the http call to the server to get the player’s current state (and update the android’s view accordingly).
So far my plan is to have the app constantly polling the server while the app is active (no need to poll when the user isn’t playing). I am wondering how quickly I should be able to poll my web service and update the phone. I would like the game to be responsive and somewhat synchronized with other players in the virtual world. Additionally, any thoughts on the load that the server will have to handle? will that be the bottleneck?
Thanks for any help! Let me know if I can clarify anything.
There are many factors surrounding speed, such as the connectivity (wifi/3g/4g/hsdpa), or server response times. or if the user is paranoid and has constructed a Faraday cage. These are just a few possibilities. You just need to do the best you can, via performance enhancements and error handling (however I would get something working to avoid early optimisation issues).
You could look at simple things like using JSON over XML as it has a smaller size or even use compression.
I would argue, although I have never done it, you could use UDP but it depends if you 100% need your packets of data to arrive. As far as I understand, TCP tried to ensure packet delivery however because of this it is slower. For example if this is some sort of FPS I would use UDP however if it is turn based then TCP would be fine.
An example tutorial for UDP can be found here: http://www.helloandroid.com/tutorials/simple-udp-communication-example
If you want to poll make sure to do so asynchronously as you don’t want this to happen in the main thread. You could use the AlarmManager as there is no need for a service although as you said “no need to poll when the user isn’t playing” you could implement your own setup
To help here are links to some Alarm and AsyncTask tutorials: