Connecting two Android phones to transfer data between them over WIFI - android

Actually i am developing tracking app and want to send Location updates between two Android phones so that both can track one another over the Map. My application must get real time updates from other android device for better tracking.
I Have searched couple of techniques but don't know which one is best
Using Sockets: making one device as Server while other as Client
Possible Limitation:
What if IP address of Server is changed (because WIFI don't have a
static IP)
Cannot access if the IP address of server is private
Only client can connect to Server and Server cannot connect to Client
Using Intermediate Server: create an intermediate server and make a communication via that server.
Possible Limitation:
Slow because each Android device first send these updates to server
and then server push these updates to other android device
Please provide me your suggestion about which one is the best way to do this.

Since you didn't state the Device API level you want to support I'll provide you with an option for Android v4 (API level 14) devices. It's called Wi-Fi Direct and allows p2p connections between phones. It's essentially your socket approach, but allows easy neighbour discovery and allows transfers in both directions.

Well wifi is out.. Not for your stated purpose at least. Unless your map is quite small. Wifi is for say 100 meters (on a really good day)
Not knowing as much about android as I do of other mobiles, I'd say you're in for some pain.
I'd suspect connecting to your phone with a peer to peer might be a real slog.. some providers won't let it happen.
I have an approach more than an answer..
From an android phone, see if you can get your ip address.
From a desk, ping that ip address.
If it works, you're well on your way..
Id even say given the size of your info, you could use pinging as your main data carrier.
Pings can contain more than just random bytes. You could include an ID, and GPS in the contents you send in your ping. --- perhaps include a check sum ---
Do most of the work desk to phone, because development would be faster.. Then when your phone is capable of catching the pings.. Well then sending the ping should be easy as.

Related

phone-to-phone data connection

I am a freelance systems administrator and architech. I have two small simple android apps that communicate with each other... One is a "server" that receives commands and the other is a "client" that sends the commands... Example: the client connects to the servers IP:Port and sends: "PC1 WAKEUP" The server executes wake on lan for PC1. Or the client sends "PC1 ls -la" and i receive the file list on the client... It works in my local network with wifi and i have configured port forwarding to access the server (an old android phone always connected to my wifi) from my phone anywhere as long as both have internet connection... And this is my problem... My home internet connection has many down periods and breaks... GSM does not...
So i want to do the same using GSM, CDMA or a direct data connection using a data call. I want to establish a data connection between the two android phones. In a similar way to connecting two PC using modems. One dials the number, the other is waiting and picks up the call and they communicate...
I have been trying to find a way to do this and i even learnd a little about XMPP and google talk but it seams to be outdated... It seams to be possible by exchanging SMSs but is not as functional and can be very expensive (and slow) for long sets of commands... I have a number of equipments at home that i need to interact with... in a fast way... I am lost here... Is this even possible? I cant find a way to do this... Any help is welcome... Even if i am looking at this the wrong way... New ideas are also welcome...
Thanks
If they're on the same wlan connection, you can do WifiDirect. Or traditional networking. If not- writing a server to run on a mobile phone is next to impossible. IPs change too frequently to keep DNS up to date, and cell networks are firewalled. You're just not going to have any reliable way to connect to a phone without a central server of some sort. You can try hacks like SMS, but remember that SMS is unreliable- messages may be dropped, or delivered days later (I just lost my phone, when I got the new one a week later I got several days worth of SMS at once- all of them with a timestamp of right now). You need a central server.

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

Android Network Discovery Service (ish) before API 14

I need to be able to discover the services on the local network (so say I am running a chat application and I want to discover other devices on local network running this chat), but sadly I need to be able to use it on devices with API < 16 (so I cannot use android.net.nsd) I am sure this can be done without using NSD API. Question is how. Any help?
There are at least three or four options.
You can use
TCP or UDP
Broadcast address
Multicast address
Iterate over all adresses in your network
HTTP
4 Make use of external server or something like GCM (Google Cloud Messaging)
ad.1 and 2
Pros:
+Easy to implement, server is sending predefined "hello" message on broadcast/multicast address of your subnet/network on specific port, client is listening on that port and when "hello" message arrives, he automatically knows server IP address (contained in packet)
+Connection to the Internet is not needed
Cons:
Some public networks blocks this addresses to avoid attacks (e.g flooding ).
ad 3.
Pros:
When Multicast and Broadcast is blocked what you can do is simply iterate over whole subnet. It is " brute force " method, but works, especially on typical home/small networks where mask is /24 - there are only 255 addresses to iterate through.
Connection to the Internet also is not needed
Cons
When mask is let say /16 it will take pretty much time to iterate all IPs
can cause battery drain
and will flood network.
ad. 4
Another approach is to make some external server that will be "orientation point" for devices. Each of them sends up its own Address, and looks if there are some entries from another devices from the same network.
Of course Internet connection is needed.
So, I think it is good idea to start with broadcast and multicast since it is very simply and will work in many places, but keep in mind that there are networks where it is not allowed to use.
Good reference can be found here http://docs.oracle.com/javase/tutorial/networking/datagrams/broadcasting.html
You should also check this one http://home.heeere.com/tech-androidjmdns.html

using android mobile as a server

I am developing a turn based two player android game. Is it possible to use one of the user's mobile as server rather than an external server to coordinate the game ?
I do not need much data storage. only 40 fields(text or numbers) to be stored and transmitted (for transmission , one value at a time) while the game is on. after game is over only user's current score is to be stored.
I guess to do any such thing I need to get ip of the mobile. Is it possible ?
You need more than just the IP since the IP is just an endpoint on the Internet and there is no guarantee that it is your device that answers if you talk to that IP. There is usually a local network behind that IP and you can't access devices in there with just the public IP.
The problematic part is establishing a direct connection which is (usually) not possible on the Internet unless you are in control over the Internet connectivity (router etc) and can setup port forwardings / firewall rules / whatever blocks direct connections. If you have no access - for example because you use 3G where the "router" is at your provider's datacenter - you will need at least a server to do things like hole punching.
Also a server used to find other's games (and IPs) would be a good idea.
You can however do all that if both devices are on the same WiFi and they can see each other directly.
I am from Skiller and I think we have exactly what you need.
#zapl is right, if you want your players to connect to your games using 3G or WIFI connection the best solution will be intermediate server that makes it possible to exchange data between the players. Setting up, hosting and scaling such a server may be very expensive and time consuming thing. We provide FREE SDK tools, using which you will be able to set up your turn based two player game in no time. We are handling all the server side maintenance so you could just implement the game logic and fire your game to the market asap.
Download the SDK from www.skiller-games.com and tell me what you think.
If you have any questions write us here or to developers#skiller-games.com

ANDROID - Displaying a list of IP addresses of phones running same app

I am developing a multi threaded client-server Android app in which both clients and the server are android phones( the server is not centrally located) and are located in the same network, under the control of one single router.
The server will start the application first. When the clients starts the app, they should get the IP address of the server phone automatically, so that when they click the address, they can be connected to the server.
Right now, I have made a provision that the server phone displays its IP address on the screen when the app starts running. When a client starts the app, it is provided with a text field in which the user can manually type the server's IP address and get connected to it.
Can anyone give me any pointers on how I can get the server's IP address to be displayed on the client phone automatically? Do I need a central database or something like that? I am new to android programming and don't really have any idea about this.
See if this is useful: Android IP address with java
You might want to think about implementing a UPnP solution. See this Universal Plug and Play as a starter then check the links at the end for relevant docs/references.
UPnP doesn't require devices to explicitly know the network details of other devices and instead they locate each other using a discovery protocol (SSDP).
One solution is to ping local IP range in a loop. Put a small timeout duration. It would be better if you run it in separate threads. If you get ping response, this would mean the server is available.

Categories

Resources