examples of implementation of NAT traversal techniques in (android ?) p2p applications - android

I am currently working on an Android peer-to-peer application.
Of course, we soon realized that one of the most difficult tasks is to figure out how to traverse NATs to allow 2 devices (or more) to communicate with each other over the internet, regardless of the distance between them.
I have been doing some research, read about STUN(T), ICE, TURN and found some implementations including Ice4j, JStun,IcedJava,NUTSS...
Would you know about examples of practical use of at least one of these techniques, possibly in existing (android or other) peer to peer applications ?
The most useful for us would be the ones that don't need the app to use any additional relay server.
Other suggestions are welcome as well!
Thanks a lot in advance :)

Just to know a device Ip and Port by NAT, other device connect to the one.
IcedJava implementation RFC5389, JStun implementation RFC3489.

AFAIK It is impossible to avoid a relay server of some sort with Android applications: the IPs allocated to the mobile devices by the telcos are not fixed and not publicly accessible: there is no way you can establish a direct connection to a mobile device.

Related

WiFi Direct the right choice? Trying to make chat app - Android

I'm trying to make a simple chat app on Android for learning purposes. I would like it to have the following features: Different "rooms" which people can create/join. Working of Bluetooth/WiFi Direct (Preferably WiFi direct). Passwords on rooms.
I'm having a number of problems however. I don't fully understand WiFi Direct. I've read and re-read the guides and references on developer.android.com and I've asked multiple times on #android-dev on freenode to no avail. Would someone be able to explain if what I outlined is even possible using WiFi direct and if not, what should I use?
TL;DR: Explain WiFi Direct's network structure and capabilities and provide resources for learning if possible.
It is possible using WiFi direct.A room can be considerd a P2P group(1 group owner+ one or more clients) .The person who starts a "room" becomes a P2P group owner and whoever wants to join a group has to undergo the authenticatio process.A client can directly communicate with owner but to communicate with other clients in the group it has to go through the owner.
For detailed understanding of wifi direct better go through the wifi p2p tecnical specification v1.2 which can be found in WiFi alliance website under published specs. Or for a overview Click [here] (http://enjambre.it.uc3m.es/~agsaaved/papers/2012_camps_wircommag.pdf).
It is possible in theory but currently the framework of wifi-direct is too unreliable..
I have tried it and the connection is very unreliable ,it breaks abruptly for no reason. Also beyond 3 devices it doesn't scale very well ,though i tested it on tablets having very less processing power (maybe on good phones it might allow one or two more connections).
So i would recommend you use wifi for communication . it would be the best suited for your needs and easier to work with as well

Does WiFi support UDP and TCP (Android device)

I've been looking around and I have found that there is evidence that Android can use UDP with it's WiFi, but can TCP be used? I know it probably can, but I can't seem to find any evidence, looking at http://developer.android.com/guide/topics/connectivity/wifip2p.html it doesn't say anything about the protocol it can use,
Does anyone have a website that states what protocols can be used, and also, I'm createing an application for android where multiple users can connect to one WiFI hotspot device and they can all play together and be real time networking, I feel UDP would be best, do you agree?
Canvas
UDP, TCP and much more network stuff is placed under java.net location
and can be found here
java.net in android api
TCP is possible I know for sure, because I've used it.
That being said I do not have any any link to a resource that states as much.
I can tell you that in order to implement it on Android I used the Socket class along with some Input/Output streams.

Android Multiplayer Game with Socket Programming

I have been searching if it is possible to develop a multiplayer game with socket programming on android platform over WiFi but I couldn't come across with a certain answer.
As I found out, there are ServerSocket and Socket classes in android sdk.
Can I use those to establish communication between 2 devices, over WiFi?
Also if I can make 2 devices connected somehow, how should I combine this with my game architecture?
Any advice will greatly appreciated. This is my first try on Android and Socket Programming. I heard about Skiller, WiFi Direct and some other stuffs but It has to be done with Sockets.
I am actually from Skiller and I will try to address at least some of your points:
Why do you need sockets for your game? It will help a lot if you will explain what exactly you are trying to achieve. Maybe there are other, less complicated, ways you can achieve the same thing. And integrating the communication solution with your game logic relies directly on that.
Directly connecting two devices, whether they are connected using wifi or 3G is a very complicated task. In order to do so you need to know the IPs of the devices and it varies from difficult (wifi - depends on the wifi you are connecting to) to almost impossible (3g - you can not see the ip of the device behind operators proxy) unless you implement couple different techniques or use intermediate servers to do that job. These solutions of course will cost you because of a hardware resources and the most important time resource. From my experience in that field I strongly recommend to use existing solutions if it matches your needs (and I am really trying to be objective ;))
Hope it helps to further investigate what you need for your game. If you want to check out Skiller SDK you are more than welcome to do that in our wiki: http://wiki.skiller-games.com/ or send an email to developers#skiller-games.com
Michael

Android, VPN, Asterisk communication

I'm trying to write a voip app for Android, using the Android SIP API (Yes, I know this only works with some Androids with version 2.3). I want calls to be routed through an Asterisk server. The calls also need to be encrypted. A problem exists where Asterisk and the Androids need to be on the same subnet (otherwise no audio is exchanged). There is a nice blog post I found at http://blog.harritronics.com/2011/06/android-gingerbread-and-asterisk-pbx.html describing the situation for those that are curious.
I'm looking to setup a VPN solution as discussed in the article as I figure this could solve the NAT issue, along with encryption. My first thought was to use OpenVPN since there is a pretty active community and the software looks pretty nice. However, after further inspection, it seems that I can only have 2 clients active on the VPN server at any given time (for the free version). Each additional client connection is $5. In short, I'm wondering if a scalable free solution exists. I would like to be able to connect somewhere around 100 android phones to this VPN to communicate with Asterisk simultaneously.
Also, I have done no VPN work previously. I'm wondering can I simply use the VPN configuration within the Android Settings? Or does there need to be an additional application? I saw that OpenVPN had a client solution for Android that only worked if the phone was rooted - this is not an option, as they are not my phones. Any advice would be greatly appreciated.
Thank you!
Not sure what you've been looking at, but OpenVPN certainly does not have any restrictions on the number of clients. Anyway, as you have found out, OpenVPN is not supported by the default Android distribution, though it is integrated in CyanogenMod. Android also has a built-in VPN client however, so you just need to find a server that works with that. As of 4.0 (ICS) it is also possible to write your own VPN implementation without rooting the phone.
BTW, the audio problem only arises if the phones are NAT-ed (e.g., connected via WiFi to your internal router, etc.). If the have global addresses, there should be no problem. If you connect over 3G that would depend on whether your carrier gives phones actual global addresses.
Another alternative is not to the Android SIP stack. There are other solutions available, and they might not have this restriction. Check sipdroid, it open source:
http://sipdroid.org/
Yet another alternative is to not try to write your own app, just use sipdroid :)
Besides the nat=yes option of Asterix I only think in one more solution. That nat option worked for me behind a router but I know that it isn't a very "inteligent" NAT traversing from Asterisk, it needs "colaboration" from the client too. The other solution could be... when I was working with that, I was using CSipSimple, it's an open source voip client for Android, may be you can look at the sources and find why that traverses works behind a router doing NAT.
If you're looking just for an Android VPN client, there are some of them, at least one with a 100% free option.
Hope that helps!

Make a mobile device a remote control for a tablet?

I'm trying to make an app on an Android device that will control an application on an iPad or Android tablet. (I'm testing with an Samsung Galaxy S2 and an iPad 2).
The application is pretty simple for now. When one selects a colour on the Android mobile, that colour displays on the tablet device.
The question is, how to connect the two devices. Just now I've verified that I can pair the two devices using Bluetooth. Also, the Samsung has a "Kies" Wifi Direct feature (which I don't understand fully), that allows the iPad to connect to the Galaxy as a wifi hotspot.
The connections are there, but I don't know if either protocol can be used to actually get the apps to talk to each other to get the control I'm looking for.
Should I be using Bluetooth, Wifi, or something else?
And in whichever case, how?
My opinion is that you should not stick so much around the physical medium used for connectivity either is WiFi or Bluetooth. You should abstract this aspect, in both cases you will be using sockets (I'm speaking about Android), if it's Bluetooth you will be using Bluetooth Sockets, if it's WiFi: TCP sockets. You could have a intermediate layer that abstracts the type of connection and through a factory to use either Bluetooth or TCP.
Bluetooth - http://developer.android.com/guide/topics/wireless/bluetooth.html
For WiFi you should study if P2P would help.
You will need two applications:
- one on the tablet - the server which listens for commands from the client (change color, do this or this)
- second on the smartphone - the client which sends commands.
I've built a few apps that do exactly that between iPhone and iPad. But the principle is the same. I used Bonjour networking. It's just a fancy name for ZeroConfig networking between devices. It's written originally by Apple but it's open source so there should be Android support out there for it too. Really simple and easy to work with.
If you already have a working connection then you already have the first half of your answer, that said you should really consider implementing a solution that uses a variety of connection types, WIFI, Bluetooth, etc.. The question I think you are really asking is how to pass data and messages between the apps once you have the connection.
There are a lot of ways to accomplish this. You could implement your own lightweight message passing system. If you haven't done this before it is more complicated than it originally seems, especially as you would be required to implement the system for each OS you end up using.
Should I be using Bluetooth, Wifi, or something else?
It depends on what situations you want your program to work in.
Bluetooth can provide a direct connection between your devices. A potential issue with bluetooth is that it has a limited range. If you're devices need to be far away from each other, you may want to go with wifi. Otherwise, bluetooth could work great.
If both devices are connected to the internet, you can make them talk to each other through there. The advantage of this approach is that it doesn't matter how far apart your devices are as long as they're both online. A disadvantage is that you'll have to figure out how to find the tablet's ip address before you can talk to it. This is actually a HUGE disadvantage because it can be quite problematic if both of your devices are not on the same wifi. You could have the user type in the destination ip address, but you'll have problems getting it to work if the user is behind a router (which will almost always be the case). The point is, it gets hairy.
If both of your devices are on the same wifi, you can use ZeroConf AKA bonjour (like Dancreek said) to figure out what ip address you need to send info to. I've previously used a library called jmdns (easy to find with google) to implement zero configuration networking. It's good because the user doesn't have to worry about ip addresses... it's intuitive for the user.
And in whichever case, how?
Networking is a pretty big topic, so I can't expand on this question to much. Short answer is, it depends on what method you choose. Search for some tutorials and start by getting one of your devices to send something as simple as an int to the other.

Categories

Resources