Best way to send messages between devices running the same application? - android

I am planning on creating an application that will allow multiple devices running the application to send messages (urls/ids/strings) to a another device running the application.
So if I had 4 devices. Device A, B, C & D. Device A decides to become the host device, devices B, C & D will then like to see Device A through the app, and then send some requests to Device A.
My challenge is picking the correct/most efficient and cost effective method of doing this.
I have considered the following options
Peer-to Peer connection
Starting and running a server on host device on the fly
Push notifications
I have deliberately avoided the user of a middle-man server as I want to avoid additional costs as I do not have any foresight on how this app will do commercially. I secondly must mention that at any one time, I would not expect more than 10 devices would want to send messages to this 'Host Device' and no more than 50-100 messages to be sent over the course of 5 hours. So not to taxing.
All the devices would be on their individual mobile networks but potentially on the same wifi. I do not want to restrict this to being on the same network.
Any thoughts on what would be the best option in my case would be greatly appreciated. I am personally leaning towards peer-to-peer as it would seem easiest to implement and would do fine with the number of requests the host device would be able to handle.
Thanks in advance,
James

Considering they may be on different mobile networks and you don't need real time communication, I would consider push notifications.
And you can have problems with peer-to-peer connection across different mobile networks, it is probably blocked. And you would waste resources to connect/disconnect for every message, because you can't keep the connection running or you will drain the device's battery.

Related

Be able to send Messages/Bytes Simultaneous to multiple devices using Nearby Connections

To try out the nearbyAPI, I decided to build an app that would allow a teacher to track attendance of student in a class.
Similar to what Caren Chang is doing.
I have gone through the google sample codes on rockpaperscissors and walkietalkie
But only a single device seems to connect at any one time when i test the samples using 4 phones.
I want to build a teacher and student app which the teacher advertises and discovers students, sends payloads to each and every connected device simultaneously as more devices become connected in a classroom set up.
How can i use nearby api to connect and send data to new and multiple devices simultaneously?
That's a great use case, and one we've talked about in the past.
If it's specifically for attendance, then you don't need to form a connection. You can have each device advertise while one device constantly scans. You'll build up a list of devices quickly that way.
If you want to do more than attendance, though, such as pushing an assignment to everyone's device, you'll need to build a mesh. To start with, you'll want to use Strategy.P2P_CLUSTER. We have 3 strategies available inside Nearby Connections (CLUSTER, STAR, POINT_TO_POINT) and cluster is the most general one. With cluster, you can connect to as many devices as you want, and you can receive incoming connections from as many devices as you want. Or, almost... The Bluetooth radio inside phones is weak and can only hold 3~4 connections at a time.
To be able to connect all ~30 devices, I'd recommend forming a 'snake-like' connection. The head and tail of the device will scan and advertise at the same time (and devices that aren't connected to anyone are considered snakes of length 1). The heads and tails will keep connecting to each other (being sure not to connect to itself*), and you'll pretty quickly have a long chain of connections connecting everyone together. From there, you can forward messages down the chain to make sure everyone gets it.
To avoid connecting to yourself, you can either assign every device a random number (eg. 1, 4, 8, 10) and each device tries to connect to the next highest number, or you can broadcast a message when connecting and disconnect if you get an echo back (because the broadcast went in a circle).

Instantly send signal to a group of mobile phones within 10 m

This question follows on from Unity3D -- Send message to other mobile phones in the same vicinity
However, I made mistake of restricting to Unity3D.
So I would like to re-ask the question without that constraint.
Let us say we have 20 mobile phone users in a cave (so no Wi-Fi networks / isGPS)
One user hits a button, and every other user's screen flashes, (within a few milliseconds)
How to accomplish this?
What if everyone is using an iPhone?
What if there is a mix of iPhone and android users?
Finally, is there any solution that would cover a wider range of phones?
You should have some network so that mobiles can share some data. Bluetooth can have maximum of 10 m distance coverage (depends upon devices though). Since, all mobile are running same app they should be linked to a network and communicate. Please Check:
http://developer.android.com/samples/BluetoothLeGatt/index.html
You can create one device as server and communicate among other devices.
https://github.com/polyclef/BluetoothChatMulti
If you have installed the app on all of the devices then in all probability yes, if the device supports push (pretty much any smartphone) then you can use the push service to synchronize the devices based on geofencing (ie, 10m from my location), there are some other discovery routes you could try to (without using the B word) pinging other devices
the app would need to be able to provide some sort of server service if it was to create its own private network based on the IP addresses of the devices it found nearby, as those devices would have to connect to that phone acting as a server. the network interface shouldn't be important, but connecting the satellite devices to the server should be. You could try doing it based on which device can provide data services, aka hotspot. You can easily connect devices to networks programmatically.
at that point your faced with the classic client server problem. There is going to be a huge amount of work to get devices configured, network creation, client server infrastructure if it has to be done without data, packet optimization. Very expensive and very high risk depending on how many restrictions there are.
Search for How to make a html5 group chat and then build on that example.
Possibly send commands to the chat delimited by a / character where a javascript could then execute the command.
Good Luck with your design.
Danny117

Simplest way to pass information between the same application installed on different phones

As the topic name suggests, what I am looking for is to add my android app the option to send data to a different phone running the same application so the receiving phone will process it accordingly.
The obvious option for me was to use app engine and use push notification with the phone number acting as the identifier.
Does a simpler solution exist?
Thanks ahead :)
The best and most robust solution is to have something like your messaging clients, in which Device A sends data to the server, which pushes it to Device B. Device B sends a reply to the server, which pushes it to Device A.
This process has the advantage of retrying the sending without requiring your users to stay connected, as may be required if Device B is offline when A sends a message.
A less foolproof solution is to have a server work as a middle man, and get each device's IP Address, and then open up a direct socket between them. In this solution, you'll lose any data that doesn't make it through.
If the devices are on the same network or in Bluetooth range, you could try Bluetooth or WiFi direct.

Network agnostic peer to peer connection on android

I need to either get an actually TCP connection between two android phones or minimally the ability to do a 4 step order dependent protocol ( A sends to B, B sends to A, A sends to B, B Sends to A) with small payloads (at worst 20kb per message )
This needs to work
without wifi, bluetooth, or nfc enabled (i.e. over 2/3/4G)
between Andriod phones and preferably between and Android and IOs as well as between iphones
Not require a third party server and preferably not require me to run a server
I am perfectly willing to make someone scan a qr code to "pair" the phones or exchange basic identifiers.
Is there anything better that I can do other than setting up my own server and running some network hole punching solution to open up a TCP or UDP stream between the two devices?
If there isn't, whats the best network hole punching solution for android?
What seems not to work:
Googles C2DM push notification seems to be meant for server to device messaging to trigger a pull.
Alljoyn seems to do exactly what I want in terms of messaging, except it appears requires users to enable wifi or bluetooth. The idea is to avoid using the cellular modem.
Android natively supports this for WiFI via this api, but again this is a non starter.
Finally, there is the Bump api , which does almost everything I want but requires a third party server. This is a no go on privacy grounds since the server learns when people use the app.

Adapting Android Bluetooth Chat for multiple devices

I'm doing a college project on Bluetooth for Android, and I'm trying to understand how to manage communication between multiple connected devices. Eventually I'm going to develop a multiplayer Bluetooth Game.
Currently I've adapted Android's sample app BluetoothChat to connect my three Nexxus One phones.
1 connects to 2 who connects to 3
1 sends its messages successfully to 2. 3 sends its messages successfully to 2 as well. 2 can send its messages successfully to 1 and 3, as it shares a ConnectedThread with both. But I can't figure out how to handle getting communication from 1 to 3.
Does anyone have any examples of communication between multiple devices or has done this themselves? Thanks
One way is to annotate your messages with the sender and receiver, so that when 2 gets the message, it knows to deliver it on to 3. When 3 gets a message, it checks the receiver attribute to know it is from device 1. This extra layer allows you to send and receive messages through other devices and still be able to know who it is from.
First, though, you'll need to figure out how to make every device know about every other device on the network. If you're just connecting in a line, like 1-2-3-4, then every time a device enters the network, you could send an updated list through the network, but what happens if 2 drops out? Do you just quit the game? Wait for it to be re-paired? In this case, it may be better to look at a peer-to-peer network, or the typical client server architecture where you let one device be the host, especially if this is intended to later be a multiplayer game.
Hope that helps!
It is possible to have multiple Bluetooth sockets in use simultaneously so you may also consider configuring to act as a server, like an IRC or XMPP server, which brokers all communication from any client to another.
If you're going for fault-tollerance (for example server socket goes down) then upon connecting to the server, it might provide a list of recently-seen Bluetooth devices which you could fall-back on in the event the server goes down.

Categories

Resources