Android 4+ devices support Wifi Direct (Wifi P2p). Wifi Direct
allows you to connect two devices over wireless without an access point.
It is similar to Bluetooth with a much extended range and performance.
It is recommended to use Android 4.1+ devices as there are several major known issues with Android 4.04 devices and Wifi Direct.
Establishing a connection over wifi direct is done in two main steps.
First you need to discover and make a peer to peer connection. This step
ends when you have the IP address of the other device.
In the second step you use the Network library (together with
AsyncStreams) to create a connection with the other device IP address.
Creating the peer to peer connection
First we should find the nearby peers by calling manager.DiscoverPeers.
The PeersDiscovered event will be raised when the process completes.
This event includes a list with the discovered devices. Note that this
event will also be raised during the connection process so your code
should be ready to handle multiple calls of this event.
Once we have a device we can call manager.Connect with the device MAC address. The ConnectionChanged event will be raised.
This event includes the group owner IP address. If the address is
"127.0.0.1" then the current device is the owner. You should use a
ServerSocket to accept incoming connections.
Otherwise you need a Socket to connect to the group owner ip.
The attached example implements a wifi direct connection and then allows
you to send a message from one device to the other. The implementation
is done with a Service. It is easier to use a Service for such tasks as
the service will not be destroyed like the activity.
BTW, I did a small test to check the maximum range until the connection
broke. The result was about 40 - 50 meters (tested with Galaxy Nexus and
Nexus 4).