24

Hi all I was wondering what options do we have to exchange data between two different android devices?

For example, User-A and User-B both installs my app. I would like User-A to send data (possibly just a simple message or user-A's location info) to User-B.

The functionality I would need is similar to the functionality that WhatsApp has. However unlike WhatsApp, I do not have a server and I was wondering if we could do data exchange between two different android devices without a server?

I was thinking we build it atop SMS or something.

Pacerier
  • 86,231
  • 106
  • 366
  • 634
  • What can you use for sending data? 3g only? wifi only? bluetooth? a mix of all these? – user931366 Jan 10 '12 at 01:59
  • I think using Bluetooth or WiFi Connection you can achieve this thing. – Lucifer Jan 10 '12 at 02:03
  • 1
    Agreed. You're not going to do this over 3g with out a sever. – user931366 Jan 10 '12 at 02:06
  • 1
    @user931366 there is nothing stopping you from using 3g infrastructure to send data to other device. Yes packets will be routed to their location but there is nothing stopping you to say that other location is phone IP address and not the server. Why you usually need a server for this is to say to the first phone which IP address you need to target in the first place. But you could send this data via SMS,Email or a piece of paper. Top voted answer explains this in more datail. – Igor Čordaš Jul 02 '14 at 14:43
  • Mess Networking is another approach you may like,which doesn't need any network connection,you can establish connection between two devices using bluetooth and use your wifi to extends you network. – Pranesh Sahu Feb 18 '17 at 10:45

2 Answers2

13

Options for exchanging information between devices are the following:

  • Bluetooth - this would be between two devices in the near vicinity
  • TCP/UDP IP connection - this would be using TCP to open a socket directly to another server socket. That could be hosted on the phone or a shared server. There are pros and cons to both.

The pros of bluetooth would be no need for a central server. The big downside is this means you can only exchange data between two people standing within 20 meter range. The other downside is you have to pair the devices which not everyone finds easiest.

You can use TCP/IP connections to exchange data just like any client-server program you write on a traditional computer. This could be used no matter if your phone is using 3G/4G/WIFI/EDGE or future radio protocols. The problem is the IP address of the phone might not be globally reachable. The IP address of the phone might be a non-routable like a private IP. They might be behind a firewall or NAT address.

This is where a central server is probably needed to either exchange IP addresses for users, or serve as a common location for clients behind infrastructure that could block. This is where protocols like SWIFT come in handy for jumping firewalls. Even with things like P2P you still run into these types of issues with non-accessible devices, and tricks like this have to be used to crawl around them. Unfortunately, that means you probably need a central server even with the P2P model.

chubbsondubs
  • 37,646
  • 24
  • 106
  • 138
  • 1
    does this mean, that I can send something over TCP/IP from Europe to USA without server in between? – 5er Dec 12 '14 at 16:04
  • TCP/IP alone between two phones with no server? No highly unlikely. Even SWIFT, STUN, etc require at least a server for discovery. You don't connect to the server to exchange data, but you need to discover each other in some way. If you knew the routable IP address then you could do it without a server, but that is an extremely rare situation. – chubbsondubs Dec 12 '14 at 16:51
3

Without an external server to keep a list of all connected clients, you would need to implement communication in a P2P fashion. Depending on the needs of your app, you could have the user type in the IP address/email/phone number of the other user they want to exchange data with.

If you wish to use a server approach, you can sign up for Google's App Engine which has good Eclipse integration as well as a plugin to easily interface with an Android app. This would give you an infrastructure option without initially (or maybe never depending on how high you scale) having to put down any money.

Google gave a good IO talk showing an example of a web app that can easily communicate with an Android app. You could extend this to do what you are looking to do.

Robert
  • 192
  • 2
  • 10
  • Is it possible to build it on top of SMS ? That is, I send an SMS from user-A to user-B and somehow my app reads that SMS and extra data from it? – Pacerier Jan 10 '12 at 02:42
  • If sent through sms all SMS client's of android will get notified. Is it ok? Don't you want only your app to have control over the content? – san Jan 10 '12 at 03:00
  • @Pacerier: It depends on what data you are sending. It is not really the best way to do it, but if you are sending short messages (144 characters is a fairly standard limit, but it does vary from carrier to carrier) it can work. – Robert Jan 10 '12 at 03:01
  • @Santhosh: Yes, all SMS clients would get notified and you would end up confusing your users a bit at first I'm sure, but if that really is the only way to do it (and security/data load is not a concern) it is possible. Back when I used my G1 on Android 1.5, Youmail used to handle their voicemail notifications this way. – Robert Jan 10 '12 at 03:03
  • SMS approach is quite feasible if you are only going to exchange contact data and then open TCP connection to transfer the data itself. Yes, every SMS handler app will get notified when you send SMS but you can specify priority and intercept the message(see http://stackoverflow.com/questions/1741628/can-we-delete-an-sms-in-android-before-it-reaches-the-inbox) and then cancel it. Be sure to use a specific pattern that you intercept and if you want encrypt this data with some key private to your application. Keep in mind it could be extracted with decompilation thou. – Igor Čordaš Jul 02 '14 at 14:54