“Android Wi-Fi P2P Networking”

baroohspottyMobile - Wireless

Jul 19, 2012 (5 years and 10 months ago)


IEEEP Students’ Seminar 2011
Pakistan Navy Engineering College
National University of Sciences & Technology


“Android Wi-Fi P2P Networking”
Android-Imagination is the Limit!!
Sanghaar Ali Malik
BE (Telecommunications Engineering)
NED University of Engineering & Technology
Karachi, Pakistan

Sehrish Jahan
BE (Telecommunications Engineering)
NED University of Engineering & Technology
Karachi, Pakistan

Noor ul Ain Ali
BE (Telecommunications Engineering)
NED University of Engineering & Technology
Karachi, Pakistan

Abstract-The main theme of this research paper
includes a brief introduction to our project
“Android Wi-Fi Peer-to-Peer Networking”. The
purpose of this research is to design and
implement a telephony program that uses Wi-Fi in
P2P (Peer-to-Peer) as a means of communication
between mobile phones at no cost. The system will
allow users to search for other individuals within
Wi-Fi range and to establish free P2P voice
connections, or to establish virtual connection
through Access Points (AP). It allows devices to
communicate with one another enabling rich peer-
to-peer social applications. We will present how a
mobile peer-to-peer file-sharing application can be
implemented using the Session Initiation Protocol
(SIP) as the underlying signaling protocol.

Keywords- Android; Wi-Fi; SIP; Java; P2P; NAT;
I. I

At first, Peer-to-Peer networks were used only
for file-sharing, e.g., Napster, BitTorrent but as time
passed, many kinds of applications have been built
using the peer-to-peer paradigm, e.g. VOIP
application, Skype. Growth of peer-to-peer
phenomenon has not only created new protocols but
also older protocols, traditionally utilized in the
client-server paradigm, and is now being transformed
into P2P protocols, e.g., P2P Session Initiation
The main objective of this research paper is to
present how Peer-to-Peer based services can be
efficiently realized in next-generation mobile
networks by using SIP with some enhancements as
the P2P signaling protocol. This thesis is divided into
two parts. In the first part, different P2P architectures
and search algorithms are presented, in the second
part, hybrid mobile P2P architecture consisting of a
Android based mobile client and a SIP Application
Server based super-peer are presented. In addition,
voice call will be supported using Wi-Fi to allow
mobile phones to communicate free of cost to each
other through P2P or through AP.
Android Operating System has several
advantages, as listed below:

A. Breaking down application boundaries
Android breaks down the barriers to building
new and innovative applications. With Android, a
developer could build an application that enables
users to view the location of their friends and be
alerted when they are in the vicinity giving them a
chance to connect. [1]

B. Openness
Android enables developers to create compelling
mobile applications. It is built to be truly open,
allowing developers’ access core mobile device
functionality through standard API (Application
Programming Interface) calls. This is true, as a
developer one can do everything, from sending short
messages with just two lines of code. [2]

IEEEP Students’ Seminar 2011
Pakistan Navy Engineering College
National University of Sciences & Technology


C. Fast & easy application development
Android will provide us an access to a wide
range of useful libraries and tools that can be used to
build rich applications. Android will enable us to
obtain the location of the device, and allow devices to
communicate with one another enabling rich peer-to-
peer social applications. [3]

Android applications are built using Java. The
Java byte code executes on an efficient and modified
virtual machine known as Dalvik Virtual Machine
(DVM) [4]. DVM uses its own library built on a
subset of the Apache Harmony Java implementation.
So we need to know basic core java but it alone is not
sufficient to leverage this great platform for creating
great applications. We need to have a basic
understanding of Java, XML, and Eclipse and object
oriented programming principle.


A. Applications
The actual application that the user interacts with
resides in this layer. [5] All the third party
applications that we create will belong to this part of
the system.

B. Application Framework
The application framework provides usable
components for the application developers on top of
which new applications can be built. It include things
like Views, Resource manager, content providers and
notification manager helping the application use
underlying standard libraries.

C. Libraries
It is the C/C++ libraries used by Android system.
These are provided to the developer through
Application framework.

D. Linux Kernel
Android uses Linux Kernel for hardware
management and providing hardware abstraction to
the rest of the software stack.
V. C

Even though hundreds of different P2P
applications have been deployed in the fixed internet,
utilizing tens of peer-to-peer protocols, there have not
been many peer-to-peer applications or protocols
available in the mobile domain. Some projects have
implemented popular peer-to-peer protocols on
mobile platforms, e.g. SymTorrent, Symella but none
of these projects have really considered the special
needs and constraints of mobile domain. Also, most
of this work has focused on one service, i.e., on P2P
Next-generation mobile networks, like Third
Generation Partnership Project’s (3GPP) IP
Multimedia Subsystem (IMS), are largely built onto
well known internet protocols, such as Session
Initiation Protocol (SIP). These protocols enable
users to establish voice and video calls, use presence
service, and many other advanced services. These
protocols cannot be used for peer-to-peer networking
as they are, but with minor modifications, a protocol
like SIP, can be engineered to function as the
signaling protocol of a peer-to-peer network.

A. Objectives and Scope
The main objective of this project is to present
how peer-to-peer based services can be efficiently
realized in next-generation SIP/IMS networks by
reusing their existing protocols as much as possible.
It is also evaluated what kind of special requirements
mobile environment poses for peer-to-peer
applications and consider those requirements in our
application design.

B. Our Contribution
Compared to other mobile peer-to-peer research,
we present a unique way of integrating a peer-to-peer
network model on top of IMS networks, where SIP is
reused as the P2P signaling protocol, i.e., for
uploading resource info from a mobile client to a
super-peer, for searching resources in P2P network,
and for initiating resource connection, e.g., file
transfer between mobile peers.
Figure 1: Anatomy of Android Application
IEEEP Students’ Seminar 2011
Pakistan Navy Engineering College
National University of Sciences & Technology


C. Peer-to-Peer Architectures and Algorithms
The P2P paradigm has not only been used for
file-sharing applications, but also for other
applications, such as instant messengers, internet
telephony, and video on demand application.

D. Architectures
Before we start the review of P2P architectures
we need a definition for P2P networking. A good
definition is:
“Distributed network architecture may be called
a Peer-to-Peer network, if the participants share a part
of their own hardware resources .These shared
resources are necessary to provide the service and
content offered by the network. They are accessible
by other peers directly, without passing intermediary
entities. The participants of such a network are thus
resource (service and content) providers as well as
resource (service and content) requesters (servent-

E. Search Algorithms
A common theme among different peer-to-peer
architectures is that the actual resource connection
(e.g., file download, streaming video, or telephone
call) happens directly between the network peers.
What makes peer-to-peer architectures different from
each other is the type of search, i.e., how query
messages are passed in the network during a search.
The major peer-to-peer architectures are
centralized, decentralized, semi-centralized, and
structured peer-to-peer architectures.
Only three of the presented search algorithms
can be considered comprehensive
in their search coverage, i.e., they find the searched
resource if it exists in the network. These are the
centralized, flooding, and DHT search algorithms.
• In the centralized search, all state
information is held in a single server.
• In the flooding search, state information in
scattered around the network – every node
knows only about its own resources. Thus, if
a node fails, only information about that
node’s resources is lost.
• DHT search, state information is distributed
among all the nodes in the network so that
every node is responsible for a part of the
resource space.

F. Requirements of Mobile Environment
• The first constraint of mobile environment is
the limited network bandwidth available for
the mobile device.
• The second constraint is the limited
computational power in mobile devices.
Thus the peer-to-peer application should not
have computationally intensive algorithms
or use large data structures.
• The 3rd constraint is the limited battery
capacity of the mobile device. By limiting
bandwidth use and computationally
intensive algorithms in the application the
battery can be conserved.
As we consider these technical constraints in the
design of mobile peer-to-peer application, we should
select a mobile peer-to-peer architecture that creates a
minimal signaling load on the mobile peer, uses no
complex algorithms or data structures, and has
efficient protocol coding.
The Dalvik virtual machine is simple Java
interpreter machine, completely optimized for
Android platform and which is developed to run on
low-end memory mobile devices. One of the
prominent aspects in Dalvik is its capability to run
along an application compilation enhancing the
runtime performance of the applications. Google
states that the credit for Androids successful
development goes to Dalvik VM, because this type of
virtual machine, delivers a good performance over
various stages of an application runtime environment,
conserving more battery-power during long run of an

A. Working with Wi-Fi
The second issue is radio selection in a multi-
radio device. Mobile devices are nowadays equipped
with several radios that support packet data
communications. In addition to their long-range
cellular radios (e.g., GSM and 3G/WCDMA), they
often have short-range radios (e.g., Bluetooth), and
medium range radios (e.g., IEEE 802.11). The mobile
device should be able to select the best radio
according to the situation, i.e., use a long-range radio
when the device is on the move, and use a short or
medium-range, high-bandwidth radio when it is in
The Android SDK provides a set of APIs for
retrieving information about the Wi-Fi networks
available to the device and Wi-Fi network connection
details. This information can be used for tracking
signal strength, finding access points of interest, or
performing actions when connected to specific access
points. This section describes how to get Wi-Fi
IEEEP Students’ Seminar 2011
Pakistan Navy Engineering College
National University of Sciences & Technology


The following samples require two explicit
permissions in the AndroidManifest.xml file.
• The CHANGE_WIFI_STATE permission is
needed when an application is accessing
information about Wi-Fi networks that can
turn on the Wi-Fi radio, thus changing its
• The ACCESS_WIFI_STATE permission is
needed, as well, to request any information
from the Wi-Fi device.
The next thing the application needs is an
instance of the WifiManager object. It is a system

so the getSystemService() method works.[1]

WifiManager wifi = (WifiManager)

Now that the WifiManager object is available,
the application can do something interesting or useful
with it. First, the application performs a Wi-Fi scan to
see what access points are available in the local area.
To perform a scan, a few steps need to be performed:
i. Start the scan with the startScan( ) method
of the WifiManager object.
ii. Register a BroadcastReceiver for the
iii. Call getScanResults( ) to get a list of
ScanResult objects.
iv. Iterate over the results and do something
with them.

B. Standard Protocol:
Traditionally, the peer-to-peer file-sharing
protocols have not been standardized by any
standardization body. There are not many
standardized peer-to-peer protocols. One that we can
consider standardized is JXTA peer applications.

Juxtapose (JXTA) is an open source peer-to-peer
platform. JXTA creates a virtual network over IP or
non-IP network, hiding the underlying protocols from
the applications sitting on top of JXTA [5]. JXTA
provides several peer-to-peer communication
services and protocols for its users:
• Peer Resolver Protocol (PRP) allows a peer
to send a search query to another peer
• Peer Discovery Protocol (PDP) allows a
peer to discover other
• Advertisements (peer, group, service, and
• Endpoint Router Protocol (ERP) allows a
peer to query for routing information to
route messages through the network
• Peer Information Protocol (PIP) allows a
peer to query for current status of another
Light weight version of JXTA, called JXME
(JXTA for J2ME) has been ported for Java enabled
mobile devices. There are two version of JXME
available; proxied version for slower J2ME devices,
and proxyless version for more powerful mobile
devices. The proxied version needs a JXTA Relay to
communicate with other JXTA nodes, whereas the
proxyless version is similar to a regular JXTA edge
node as it does not need the relay.

D. Mobile Peer-to-Peer over SIP
Next-generation mobile networks, like the Third
Generation Partnership Project’s (3GPP) IP
Multimedia Subsystem (IMS), are largely built onto
well known internet protocols, such as the Session
Initiation Protocol (SIP). These protocols are well
understood and documented, and they are tested in
large scale deployments. To enable mobile peer-to-
peer communications in next-generation mobile
networks, we have designed a mobile peer-to-peer
platform that works on top of SIP. Using SIP instead
of a proprietary peer-to-peer protocol ensures that the
peer-to-peer platform can be easily adapted to
tomorrow’s SIP-aware mobile networks.

E. Mobile Peer-to-Peer in IMS
The IP Multimedia Subsystem (IMS) was
designed to be the IP-based core of the future packet
switched 3G networks. It is a collaborative effort of
the Internet Engineering Task Force (IETF) to bring
the cellular networks to a new era of
communications. The idea behind IMS is to provide
internet services anywhere and anytime for the
mobile users and to create a common platform for
various multimedia services. IMS enables rich
communications between mobile terminals over
various access network technologies, be it 3G, 4G, or
As IMS is built on well defined standard
protocols like SIP, it provides a good basis for
building a mobile peer-to-peer platform. SIP has
properties that are useful for peer-to-peer
applications, and with minor modifications it is
suitable for peer-to-peer application signaling.

F. Session Initiation Protocol (SIP)
Session Initiation Protocol is a protocol for
creating, modifying, and terminating multimedia
sessions between two or more participants. SIP is an
end-to-end signaling protocol; SIP messages are
routed via SIP proxies from the originator to the
IEEEP Students’ Seminar 2011
Pakistan Navy Engineering College
National University of Sciences & Technology


target user. SIP entities have a peer-to-peer
relationship between each other, thus any entity can
send the initial request and any entity is capable
receiving requests. During a single transaction, the
entities are in a client-server relationship, where the
request sender functions as the client, and the party
who sends the reply, as the server. Users can publish
the availability of one or more resources in their
devices, perform searches, initiate file downloads,
join audio or video streaming sources, conferences,
or chat rooms. File transfer is done using the
Message Session Relay Protocol (MSRP), and
Network Address Translation (NAT).

G. SIP Signaling
When a User Equipment (UE) joins a network, it
publishes information about its shared resources to a
P2P AS. When the UE performs search it sends a
search request to the P2P AS. The P2P AS provides
search results that contain a list of available resources
and SIP URIs where these resources are available,
e.g. content cache, streaming server, chat group
manager, or other UE where the resource is stored.
To fetch a resource, the UE initiates appropriate SIP
session towards such endpoint to fetch the resource.
This final SIP session is between the resource holder
and the requester and it does not involve the P2P AS.
Android provides an API that supports the
Session Initiation Protocol (SIP). This lets us add
SIP-based internet telephony features to our
applications. Android includes a full SIP protocol
stack and integrated call management services that let
applications easily set up outgoing and incoming
voice calls, without having to manage sessions,
transport-level communication, or audio record or
playback directly. [3]
Here are examples of the types of applications
that might use the SIP API:
• Video Conferencing

Instant Messaging

Class/Interface Description


Handles an Internet audio call
over SIP


Listener for events relating to a
SIP call, such as when a call is
being received ("on ringing") or
a call is outgoing ("on calling")

Provides APIs for SIP tasks,
such as initiating, SIP
connections, and provides access
to related SIP services

Defines a SIP profile, including
a SIP account, domain and
server information

H. Creating a SipManager
To use the SIP API, our application must create a
object. The SipManager
takes care of
the following in our application:
• Initiating SIP sessions
• Initiating and receiving calls
• Registering and unregistering with a SIP
• Verifying session connectivity

I. Registering with a SIP Server
A typical Android SIP application involves one
or more users, each of whom has a SIP account. In an
Android SIP application, each SIP account is
represented by a SipProfile
A SipProfile
defines a SIP profile, including a
SIP account, and domain and server information. The
profile associated with the SIP account on the device
running the application is called the local profile. The
profile that the session is connected to is called the
peer profile. When our SIP application logs into the
SIP server with the local SipProfile
, this effectively
registers the device as the location to send SIP calls
to for our SIP address.
This section shows how to create a SipProfile
register it with a SIP server, and track registration
events. [3]
We create a SipProfile
object as follows:
public SipProfile mSipProfile = null;

SipProfile.Builder builder = new
SipProfile.Builder(username, domain);
mSipProfile = builder.build();

J. Making an Audio Call
To make an audio call, you must have the
following in place:
• A SipProfile
that is making the call (the
"local profile"), and a valid SIP address to
receive the call (the "peer profile")
• A SipManager

K. Receiving Calls
To receive calls, a SIP application must include a
subclass of BroadcastReceiver
that has the ability to
respond to an intent indicating that there is an
incoming call.

In this paper, we presented our SIP based mobile
peer-to-peer architecture. Our application architecture
is based on the hybrid peer-to-peer architecture where
network operators are running super-nodes in their





IEEEP Students’ Seminar 2011
Pakistan Navy Engineering College
National University of Sciences & Technology


networks as SIP P2P Application Servers. Our
application architecture satisfies all requirements for
a mobile peer-to-peer application.

A. Objectives Revisited
The main objective of this thesis is to present
how peer-to-peer based services can be efficiently
realized in next-generation SIP/IMS networks by
reusing their existing protocols as much as possible,
and to present some enhancements to these protocols.

B. Results
Compared to other mobile peer-to-peer research,
where the research has often focused on the peer-to-
peer protocols used in the fixed Internet, and on
modification of these protocols to be used in the
mobile environment, we present a unique way of
integrating a peer-to-peer network model on top of
IMS networks. We have considered the special
requirements of the mobile environment in our
research, and built the application architecture
considering how to meet those requirements best. In
our architecture, SIP is reused as the peer-to-peer
signaling protocol, i.e., for uploading resource info
from a mobile client to a super-peer, for searching
resources in the peer-to-peer network, and for
initiating resource connections, e.g., file transfers
between mobile peers. Use of mobile peer-to-peer
services can provide mobile operators cost savings as
the service infrastructure is distributed among the

The research has been done by the authors, Mr.
Sanghaar Ali Malik, Miss Sehrish Jehan and Miss
Noor ul Ain Ali. We thank also all those persons who
assisted us and provide us with the interesting
feedbacks and discussions, especially Mr. Syed
Abdul Ahad Kareem, student of BE-
Telecommunications, NEDUET for his untiring
assistance in the research, and Miss Hira Mariam,
Lecturer, NEDUET for her remarkable support and
careful review of the paper. Finally, we are grateful
to Mr. Shoaib Ali Khan, Transmission Engineer at
Multinet, and particular to Mr. Dinar Ali Qadri,
Software Developer at FreeLancer. Without their
tremendous support our research would have not
been possible.

E-Books studied for the Research Paper
[1] http://www.netbks.info/others/sams-teach-yourself-
[2] http://www.amazon.com/Teach-Yourself-Android-
[3] http://www.amazon.com/Professional-Android-
[4] http://www.amazon.com/Android-Wireless-
[5] http://www.ebooks.com/ebooks/book_display.asp?IID=

Websites visited:
[1] http://www.amazon.com/Android-Wireless-
[2] http://ebookstore.sony.com/ebook/shane-
[3] http://android-developers.blogspot.com
[4] http://it.toolbox.com/wiki/index.php/Dalvik_virtual_ma

[5] http://java.sun.com/developer/Books/networking/jxta/jx
[6] http://www.informit.com/articles/article.aspx?p=27302
[7] http://www.tmcnet.com/sip/1106/sip-speaking-sip-
[8] http://www.broadnets.org/2004/workshop-
[9] http://developer.android.com/guide/topics/network/sip.
[10] http://developer.android.com/
[11] en.wikipedia.org/wiki/Wi-Fi
[12] en.wikipedia.org/wiki/Java_(programming_language)
[13] en.wikipedia.org/wiki/Peer-to-peer
[14] www.wifinotes.com/
[15] www.skifactz.com/wifi/wifi_sip_phone.htm
[16] www.globalcache.com/support/wifitutorial/
[17] www.wi-fiplanet.com/tutorials/.../Wi-Fi-Hotspot-
[18] www.securitytube.net/WiFi-MAC-header-(Part-1)-
[19] forums.comodo.com/.../nintendo-wifi-connection-
[20] www.p2pnet.net/categories/p2p
[21] www.p2p-blog.com/
[22] www.p2psip.org
[23] www.oracle.com/us/technologies/java/index.html
[24] www.ies.co.jp/math/java/download.oracle.com/javase/
[25] www.java2s.com/Tutorial/Java/CatalogJava.htm
[26] www.ibiblio.org/java/javatutorial.html
[27] www.java2s.com/Tutorial/Java/...PDF/Catalog0419_