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.
Related
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
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.
I am currently developing an android application which requires two devices to communicate over TCP (I can't silently loose packets so UDP is out). I need the communication to be as fast as possible (i.e. I have a low acceptable latency threshold) but the connections will be short lived (likely less than 2min). The phones will connect, do their thing, then close the connection.
I have done quite a bit of research regarding NAT hole punching, but there does not seem to be a reliable tcp hole punching method implemented for java and android. Thus, it seems my only option is to develop a server application which will "proxy" the tcp communications between the two devices.
I have two questions:
1) I don't want to re-invent the wheel: is there a simple tcp proxy already written I can use? (note: not an http proxy of any sort - because I need low latency I am simply looking to pass a very small payload between the two tcp socket connections on the devices). The sole purpose of the server is to avoid NAT issues.
2) If not, does anyone have experience with this sort of thing and what would they recommend? I have played around with the idea of Java NIO or perhaps a server that creates a new thread for each connection (the problem being how to link the appropriate "client" threads to pass the information back and forth). Or is Java even the best language to use for the server end?
I have read some recommendations of using XMPP via google's chat services (see here) but I don't want the overhead of XMPP.
Any direction or suggestions would be greatly appreciated.
As for the direct answers to your questions:
1) Not a good one I have found, it really depends on what's available on your server. I did write one some time ago in PHP and was VERY quick and simple and will work with most servers. I used this as a guide http://devzone.zend.com/209/writing-socket-servers-in-php/
If you can run a compiled C++ binary you could look here, it was an alternative we considered:
http://tcpproxy.codeplex.com/
2) see answer to 1 for PHP option, I don't have experience in writing from scratch in Java.
As an aside on NAT traversal... I have been investigating the same NAT issue for project I am working on and I found 2 options that would require the NDK but could work well for NAT traversal on Android.
pjnath (GPL):
www.pjsip.org/pjnath/docs/html
code.google.com/p/csipsimple/source/browse/trunk/pjsip_android/?r=201
libnice(LGPL):
nice.freedesktop.org/wiki/
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!
I'm working on some apps for the android platform and I have two problems that I'm not quite sure how to approach, and both are closely related.
How can I send a relatively small data file from one android device to another (preferably over the internet or directly through wireless network)?
Is it possible to create a temporary p2p live data stream from one android device to another? An example application would be to stream low-res video from phone A's camera to phone B, or audio.
I would much appreciate being pointed in the right direction on either issue (File transfer or real time data transfer).
You could try to get Google's library libjingle to work on Android. It provides quite advanced NAT Traversal capabilities, which should be able to get through the carriers' firewalls.
One approach would be to use the socket classes in java.net.
To use WiFi to send data among devices, you can try to establish an ad-hoc network among the devices that will communicate. I think you can use Android's WiFi API to do that. Once you have the ad-hoc network setup, you can establish a simple TCP connection between the devices and transfer the files.
Sockets do not work between phones. I've tried with two actual phones using socket communications and there seems to be a firewall in the carriers that prevents communications on ports different than port 80. Then if you try to use port 80 you get a 'Permission Denied' exception.
One possibility is to investigate the JXTA framework. The Practical JXTA II book is available online for reading at Scribd.