Android, VPN, Asterisk communication - android

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!

Related

Is it safe to assume all web-enabled devices have access to localhost/loopback/127.0.0.1 - even with "networking" turned off?

I'm working on a project that I'd like to work offline.
Now it turns out that a major piece of infrastructure I'd like to use abstracts a major component only via a webservice.
I can provide all the data needed for the webservice in the local filesystem and make my own abstraction between it and the piece of infrastructure I mention.
Ideally I would've liked it if an abstraction had been made just as a regular object with methods that I could provide but the people behind it are only interested in the serverside case running on Unix-like operating systems where network access is a given.
They have recommended the best way for me to interface with it is to make my own webservice which implements the same functionality as a small locally running server on localhost.
But I'd like my project to be able to run on any devices including Windows, Android, and iOS.
Is it true that I can expect all these environments to be able to connect to a local server on localhost even when they have "networking" turned off?
I put scare quotes around "networking" because I don't own a smartphone or tablet but I know there is a deal of foolproofing to protect nontechnical users from malware, etc. Laptops often have a switch or hotkey to turn Wi-Fi and other networking on/off so I assume other devices do too and I assume they may not all work the same. Maybe some turn off just Wi-Fi while others might disable all networking at a low level ...
(I understand if it's decided to move this question to Programmers or Superuser but I see it as a programming problem so I'm asking on Stackoverflow.)
Among the platforms you mentioned, only Windows has the ability to use localhost with wireless and all ethernet adapters turned off. You would have to install Microsoft's Loopback Adapter, which is one of the optional components you can get to from Add/Remove Programs. iOS does not offer a loopback option, and I don't know if Android does either.

Connecting two devices using libgdx

I'm developping a video game on both pc and android using libgdx.
And i would like to connect them by Wifi or Bluetooth on a local network. The idea is to play in p2p, establishing this connection easily.
Please anyone can give help or source code for that, knowing that the connections can be : android/android but also PC/PC (since libgdx allows that)? I have absolutely no idea.
Thanks
Well because libgdx doesn't have good networking support you can write your own, but i've found that Kryonet is very good. It takes a lot of the hassle out of writing the network layer of your application and I've used it to connect mobile and desktop with no problems. Definably worth a quick view. It also has some good examples to get your up and running with a network game too.
I've also found this article by valve very usefull.
Networking is somewhat beyond the scope of Libgdx. There is some basic support for HTTP GET/POST/PUT, but it implies you already have a DNS name or IP address to connect to, which usually implies you have a relatively fixed "server" to connect to (not an arbitrary peer). Peer-to-peer networking is definitely beyond the scope of Libgdx.
On the upside, since Android and Desktop networking are already pretty close, you can use most any pure-Java networking infrastructure that supports peer-to-peer. See other Stack Overflow questions like: Peer-to-Peer communication options I think you'll discover that the really hard part of peer-to-peer networking is "discovery" (that is figuring the address of the peer you care about).
There is little to no documentation on it, but LibGDX does have a platform independant (Android, Desktop, iOS and GWT) socket class.
I'd link you to an example of it's usage, but as I stated; there's no written documentation/example.
However, I can give you this link as a good starting point.
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/Net.html
libgdx-net looks good. https://github.com/pepedeab/libGDX-Net
Ive not yet tested it myself though.

Passing values from an android device to another

Is it possible to pass a value from an android device to another? I mean, without using the Internet. My project will be implemented only on a localhost. The two android devices are only connected through the router. If it is not possible on the local area network how can I do this? Are there other ways? I'll use the Internet or any other options if possible. Links to open source code, if you have any particularly regarding on this topic, would be appreciated too. Thanks!
If your target is Android4.0+ you can use wifi direct as #pgsandstrom stated.
In other cases if you want to make client/server comunication with two android decices you should look at this thread Socket Server/Client with two Android devices and the awser to this question may be usefull to you too How to write an Android SocketServer to listen on wifi.
If you can restrict usage to Android 4.0 or later, then have a look at wi-fi direct. It doesn't use a router thou, so I hope that isn't a restriction. If you need to support older devices, I think you have to go with bluetooth.

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

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.

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