Latency on mobile networks (Android) - android

I am planning to give mobile phone development a shot and was thinking about making some simple multiplayer games. I know latency over local wifi is probably fine but what are the issues with latency over GPRS/3G?
I've searched and the best I've seen is someone saying it was 'high', without presenting any concrete numbers. I suppose latency fluctuations are important as well - does anyone have any info on this?

From my laptop with a UMTS/HSDPA card to my web server I get a ping time of 100ms (both are in Germany).

I've seen the same 802.11 link with the same hot-spot jump from ~80ms to 3000ms and back. Assume latency suck and write the program to deal with it.

Related

Working behind the NATs - a scheme for device communication

I'm trying to come up with a solution enabling data exchange between an embedded device (xMega128(C) based) and an Android apps. The catch is the data exchange must be conducted via the Internet and both the embedded device and the mobile device running the app can be behind different NATs, connecting using different ISPs, 3G, LTE, etc.
I tried UDP hole punching, but it does not work with symmetric NATs. Multi hole punching with prediction also does not guarantee 100% reliabilty. I also considered using ICE, but ICE C libraries (pjnath, libnice) are incompatible with the hardware chosen (libs require os). Right now I'm considering implementing or use (if exists) traffic relay server, but that just seems like a hack to me.
Are there any other options I hadn't considered? Any help will be appreciated.
Ideally, the communication scheme would be:
100% reliable
relatively low-latency (3 seconds absolute max)
scalable (say up to 500k devices in the future)
initializable by both the app and the device
multi-user – one device would connect to many android apps
Also, if this helps, the data exchange between the device and the app is not very high-intensity – roughly 1 session per hour, ~50 messages per session with 10-20 seconds between them, each message weighing around 100 bytes.
What you're describing is effectively peer to peer or a subset thereof and to get that working reliably is a lot of work. Where peer to peer fails you normally fall back to a relay server. It can be done but the amount work to do it is quite large. Your list of requirements is also quite steep...
100% reliable
There's no such thing as a reliable connection. You need to build in fault tolerance to the app to make it reliable.
relatively low-latency (3 seconds absolute max)
Quite often you will be limited by physics ie speed of light. Low latency is hard.
scalable (say up to 500k devices in the future)
I don't know what this means ie is this concurrent connections?
From wikipedia on NAT Traversal
Many techniques exist, but no single method works in every situation
since NAT behavior is not standardized. Many NAT traversal techniques
require assistance from a server at a publicly routable IP address.
Some methods use the server only when establishing the connection,
while others are based on relaying all data through it, which adds
bandwidth costs and increases latency, detrimental to real-time voice
and video communications.
ie it will work sometimes ie it will be unreliable so you need to user several methods to make it reliable.
As long as both endpoints are behind different NATs you don't control, it won't work reliably. No way. You need a relay.

Is about 0.5 seconds of latency a usual thing in mobile gaming multi-peer networks?

So I have been experimenting with multi-peer networks. Ultimately I am going to try to use different frameworks to make one that can connect devices of same os through Bluetooth and WiFi, and ones of different types through wifi.
My first shot was apple's Multi-peer Networking. Unfortunately I got had about 0.5 seconds of delay (I didn't actually calculate this just an estimate) before even one bit of information actually got to the other device. I am suspicious that the framework is optimized for larger and encrypted data way more then it is for 1-32 bit jobs.
I was just wondering what you guys knew about the latency of other frameworks out their, since it takes a decent chunk of time for me to learn how to use each new framework. Is latency of about 0.5 seconds the best the industry has?
Honestly I would be happy if their was a library that was optimized to send 1 bit to each connected device every (1/60th) of a second. But I think most of these networks package up the data like its of bigger size anyways.
I sorta wish mobile devices had NFC. Just look at systems like the 3ds that can do multi-peer multiplayer (smash-bros) with really really small latency and great accuracy.
Try changing the MCSessionSendDataMode to MCSessionSendDataUnreliable
MCSessionSendDataUnreliable
Messages to peers should be sent immediately without socket-level queueing. If a message cannot be sent immediately, it should be dropped. The order of messages is not guaranteed.
This message type should be used for data that ceases to be relevant if delayed, such as real-time gaming data.
but depends how reliable you really need the data to be, but on a closed network, it should be very reliable anyway

How to calculate connection speed

I'm developping a radio app and I need to know if the user's connection speed is fast enough, if it's slow I'll show a message saying that the streaming may be slow sometimes.
The problem I'm having is in calculate the speed connection from the user.
I've read some opinions about that and I only found answers based on internet type (2g, 3g, wi-fi). I found this answer : Detect network connection type on Android that is almost what I needed, but the method "isConnectionFast" isn't accurate because it doesn't make a real test connection, it's just based on some properties.
I think that the best way is to download an image with a determinated size and calculate the time that took to finish the download. But I'm not knowing how to do that in android.
Can anyone help me ? Thank you
Well it seems that you already know the basic steps for doing a speedtest but I would like to explain why is that probably a waste of time in this case.
If we're talking about cellular connections there are standards that specify the speed and the answer you linked is an example of how to get an estimate based on that. Sure, you will never get the full speed and the speed test would provide a better estimate but just for that moment in time. There are many factors which may influence client's speed and most of them are changing every second so the test you made at the beginning is pretty much useless if the client is mobile. For wifi estimating the speed is a bit harder without a speedtest because the bandwidth is usually not limited by the technology but the plan user is paying for. Anyway those speeds are almost certainly enough for a radio stream.
You didn't provide much info about the streams itself but from my experience (as a user) for 128kbps streams everything above EDGE is sufficient, providing your buffering is enough to compensate for short speed degradation or connection losses caused by handoffs etc.

Should we provide dedicated servers for our mobile multiplayer game?

We are developing a synchronous multiplayer game. As it stands one of the players is selected as the server instead of connecting the clients to a dedicated server.
With the restricted environment of mobile apps, should we still be worried about cheating (from the player running the server) or is this a non issue in the mobile space? Are there any other major concerns we should look out for if we decide to stick with players hosting the game?
All of the below is about Android. iOS is more secure, but the server load issue still applies there too.
If you store game data on the SD card, any app can access that data. You could encrypt it, but it would still be a liability (like the Whatsapp hack here: techcrunch.com/2014/03/12/hole-in-whatsapp-for-android-lets-hackers-steal-your-conversations/)
If someone were to implement a low-level interception / modification of your game server network traffic, this could also be a problem. (http://www.justbeck.com/modifying-data-in-transit-to-android-apps-using-burp-and-backtrack-5/)
If you are using a Service, make sure it's a local service so it's only accessible from your app.
Also, the "restricted" aspect of Android systems can be easily removed by rooting the device.
Another thing to consider is network and cpu load. Both these things could grow big very fast, making the server laggy or even crash, considering the relatively low capacities of Android devices as compared to dedicated servers. Of course, this depends on the amount of work the server has to do per client.
In general, dedicated servers are a good idea, even for Android games I think.
I'd look into this from two different point of views:
Cost/Benefit: have in mind that dedicated server will impact your budget, so ask yourself if cheating is really a concern or not. I'd treat mobile space as other kind of spaces.
Game quality: As #1 is your point of view, this is your players point of view... They are going to feel something is going wrong and think about cheating? maybe. You can fix this with a reputation of the player that is hosting the server.

How to set up an android peer to peer networking for a game?

So after finding out how to make transparencies in my images, i was able to use some of my friends images properly for our game. Our goal was to have a game where 3 people who were next to each other, could play the game together. The idea was that you would point and click and fight off waves of little bad guys. I have the point and click, the shooting, the spawning bad guys, and the collision detection ,but now I want to learn about peer to peer networking on the android? Or is this not how you network? Am i completely wrong? How would you set up a basic network of no more than 4 local people? stack overflow said that was opinionated, but i was just more curious of ways to avoid common pitfalls and where to turn for this.{
Thank you,
There are a couple different ways you can do this, it really depends on which one is the best fit for your situation.
If you want a complete ad-hoc approach and you have the right phone, take a look at Wifi Direct.
Use a Web server to coordinate message exchanges
Depending on your Game and the distance between players you may be able to use a small Bluetooth network
As dbryson suggested, you can use WiFi Direct. However it only works for OS 4.0 ICS and higher. Here are some links:
http://developer.android.com/guide/topics/wireless/wifip2p.html
http://developer.android.com/resources/samples/WiFiDirectDemo/index.html

Categories

Resources