Home > Articles > Programming > Java

Building P2P Applications

  • Print
  • + Share This
Examine a variety of P2P applications and the architectural issues that need to be resolved in order to build them.
This chapter is from the book

In This Chapter

  • Instant Messaging

  • Managing and Sharing Information

  • Collaboration

  • Distributed Services

Chapter 1 introduced the wide world of P2P. It might have appeared that the definition of P2P is problematic—well, it is! P2P can be so broad in scope and definition that getting one's arms around P2P can be an enormous task. P2P came about as an answer to user needs for Internet-enabled application software. The Internet is always evolving and offering up new technologies, techniques, and user behavior every day. P2P is evolving along with the Internet, so fixed definitions do not usually last long.

Each new advance in Internet technology can either help Java developers working on Internet applications, or become a huge headache. For example, there was a time when Network Address Translation (NAT) routers were banned from networks. As you will see later in this chapter, they are now used widely, and a Java developer building a P2P application needs a solution to the unique one-way routing provided by a NAT router.

An easy way to get your arms around a P2P definition is to look at the functions delivered by the most notable P2P applications, including the following:

  • Instant messaging

  • Managing and sharing information

  • Collaboration

What started out as simple file sharing, such as exchanging music files, has grown to include a wide array of applications and services. These are grouped under the umbrella term distributed P2P services. These include network and infrastructure software to enable

  • Distributed processing (grid computing)

  • Distributed storage

  • Distributed network services

Although many of these applications began as ways to distribute stolen copyrighted music and video files, P2P has reached a level of maturity that is no longer confined to personal, casual use, but rather to build e-market hubs, corporate infrastructure, and Internet-enabled applications. In addition, single-function P2P applications are giving way to multifunction service-based architectures. For instance, it is common to aggregate instant messaging, file sharing, and content management to build distributed collaborative P2P applications.

Next we will look in depth at these applications and the technology that enables them.

Instant Messaging

Although Web publishing and browsing is the killer application for the Internet, instant messaging is the killer application for P2P. Instant messaging (IM) enables online users to communicate immediately and in real-time, one-to-one or in a group. It has become popular on the Internet among young adults, and is gaining popularity in business settings, too. For example, even IBM's Lotus group offers an IM product for business use. IM has gained recognition as a useful application, and most major Internet players offer IM services—AOL, Microsoft, and Yahoo! all offer IM functionality. New players are promoting niche products for e-commerce and supply chain management. There has been some market consolidation as lesser offerings have been eliminated, but there is still tremendous growth and opportunity.

With IM, users activate a special piece of client software that communicates with a central server and registers the user as being online. This user registration is mapped to an identity, such as a nickname or screen name. The user is then able to invite others to a conversation, or can be invited. IM servers communicate using an IM server protocol that enables messages to be relayed across the Internet. This interconnected IM network forms an IM cloud, or backbone, as seen in Figure 3.1. Most servers support a proprietary protocol, which has made it difficult for IM users to communicate across multiple IM systems.

Figure 3.1 Traditional instant messaging systems enable users to exchange messages through a proprietary IM cloud.

Unlike email, in which a message is stored and delivered once the user has connected to an email server, IM systems provide immediate end user delivery. If the user is not available, the message can be saved until the user comes online, or it simply may be discarded. To avoid this uncertainty in delivery, IM systems provide a "buddy list" or roster that provides a mechanism to identify a user and determine the user's online status: for example, online, offline, or unavailable.

If the user is online, you can send text messages that are immediately delivered to the user. This promotes a two-way conversational style of communication with minimal delay. Tight integration between clients and servers enables instant messaging services to provide varying levels of security, online status, and reliable messaging, as seen in Figure 3.2. The client protocol defines the message structure necessary to communicate short text messages. The server protocol defines the higher-level services, such as routing, presence, and security.

Figure 3.2 Instant messaging systems define a client and a server protocol.

Applications of presence (online status) and instant messaging currently use independent, nonstandard, and non-interoperable protocols developed by various vendors.


Under the covers, IM systems provide identity, presence, and security using IM protocols.


Fundamental to the operation of any IM system is the need to uniquely identify users. IM identity is modeled much like email identity. For instance, your email address might be myName@domain.com. Similarly, your instant messaging address might be identified by myName@imdomain.com. IM systems support name aliases to simplify usage, so myName@imdomain.com can be aliased to p2pgeek. The server or client maintains a mapping between addresses and aliases to make the system more user friendly.


Presence is the online state of a user or application. Presence is a concept important to conversations, because it enables participants to enter or leave a conversation, and make other participants aware of their status.

A presence service provides a means for finding, retrieving, and subscribing to changes in the presence information of other users. This is especially important with instant messaging systems. Presence determines whether a specific user is online and available, whereas identity uniquely identifies that user within the specific IM domain.

Presence services are becoming more sophisticated, and are not limited to simple online/offline state information. Contextual information can be maintained to convey location, activity, and application-specific data. Presence information provides the context necessary to support P2P conversations. In addition, sophisticated presence services can provide status, identity, and location information to enable application-to-application communication.

Buddy lists are part of IM presence technology. A buddy list, also called a roster, defines a list of members of your messaging group or community. Members of your roster may be colleagues, friends, or associates that you communicate with regularly. They ultimately are peers that you trust.


IM is all about dynamically and rapidly grouping users and applications together to form working teams. It is counterintuitive that IM service providers would cause their IM protocols to be closed and proprietary.

The popularity of instant messaging and the growth in instant messaging systems has resulted in an increased demand for IM interoperability. Most instant messaging systems work only if the sender and receiver are using the same instant messaging software.

The protocols defined to exchange information, such as presence, messages, and identity are proprietary to the vendor. Software developers have resorted to building gateways or multi-headed clients to integrate disparate systems. However, the complexity and maintainability of the client can be limiting. Figure 3.3 illustrates communication with the Internet Relay Chat (IRC), AOL Instant Messenger (AIM), and MSN systems.

Figure 3.3 Multi-headed clients enable a user to communicate with multiple IM systems.

Of course, this solution puts a heavy burden on the client software. The software must be able to interoperate with different messaging structures, presence and identity identification, and different feature sets and security models offered by IM providers. There are also legal ramifications to usage, spam implications, and resource sharing that must be considered.

An approach being promoted by some of the larger IM providers is to provide a mechanism for the services themselves to interoperate. This is similar to how email works today. The interaction between instant messaging clients and associated servers remains the same. However, servers communicate with other servers to exchange presence information, messages, or other data, as in Figure 3.4. This approach preserves existing IM models. In addition, it helps protect investment by the larger participants in established IM communities. Clients "speak" a proprietary protocol, but IM servers use a standard open protocol. Servers must mediate message and protocol disparities and serve as a gateway to other IM systems.

Figure 3.4 Interoperability is achieved at the service level.

The Internet Engineering Task Force (IETF) (http://www.ietf.org) is developing what will likely become the standard protocol for instant messaging, called the Instant Messaging and Presence Protocol (IMPP). The goal of the IMPP Working Group is to define a standard protocol, so that independently developed applications of instant messaging and/or presence can interoperate across the Internet. The requirements being addressed include the following:

  • Namespace and administration

  • Scalability and performance

  • Access control

  • Network topology

  • Message encryption and authentication

  • Internationalization

For more information, go to http://www.imppwg.org. Standardization work is progressing, but adoption has been slow as vendors try to secure a dominant position with their current product offering.


Instant messaging does not define a mechanism for secure communication. However, many commercial IM vendors have incorporated Public Key Infrastructure (PKI) digital certificates to add security and privacy to IM communication. IBM Lotus Sametime, for example, moves IM protocols over Secure Sockets Layer (SSL) connections. Messages, connection information, and identity are maintained on servers administered and controlled by the provider of the IM service. Most services provide a certain level of encryption, but there have been numerous security breaches on IM systems. This is one area that is changing, as new P2P entrants attempt to differentiate their product offerings through enhanced security.


Because instant messaging has become so popular, it is not surprising that there is an abundance of IM providers. Today, many P2P applications are including an instant messaging component. It is envisioned that as businesses link their manufacturing, distribution, and sales processes, more reliance on IM features will be the result. Many Web sites already use IM as a key component in their customer relationship management (CRM) strategy.


Internet Relay Chat (IRC, http://www.irc.org), is often cited as the original chat medium on the Internet. It is the forefather to many of the IM protocols that have been developed. The IRC protocol was designed for use with text-based conferencing. The IRC protocol is based on the client-server model. A server forms a central point for clients (or other servers) to connect to, and performs the required message delivery, multiplexing, and IM functions.

Over the years, IRC has been expanded and changed to resolve scalability problems. For example, while the original IRC protocol required a single central server, today's IRC enables federations of interconnected servers to pass IM messages. OpenProjects.net (http://freenode.net/) provides a backbone of IRC servers that developers and users working on open-source projects use. IRC continues to evolve.


AOL Instant Messenger (AIM) is one of the most popular instant messaging programs. With 30 million users and 2.3 billion AIM messages passed every month according to Juniper Media Matrix, AOL has the largest single installed user-base on the Internet. AIM is so large that AOL had to pledge to provide interoperability with other IM networks as a prerequisite to the Time-AOL merger. AIM is the best example of open standards and interoperability colliding with capitalism. Attempts to open the AIM network have clashed with AOL's modification of the protocol to remain incompatible. Even today, AOL has shown how slow it can be to open its network.

AIM technology is designed around a system of interoperating servers to route IM messages, provide presence service and security. AIM uses the AOL directory service for authentication and provides client software on several platforms.


Jabber (http://www.jabber.org) is an open source instant messaging platform being developed by the open source community. One of the features that distinguishes the Jabber system from existing instant messaging services is its open XML protocol. The Jabber protocol has been submitted as an IETF Request For Comments (RFC).

Jabber is attempting to build the interoperable protocol that all IM vendors will support. This would enable the interoperability that is envisioned by the IM community. In the meantime, the Jabber architecture is built on pluggable transport modules that communicate with specific IM systems, as seen in Figure 3.5.

Figure 3.5 The Jabber architecture from http://www.jabber.com.

The idea is that you use the Jabber XML protocol (XMPP) from the client to the Jabber server, and the server loads an IM-specific transport module to interoperate with the proprietary IM system.

Jabber's XML protocol contains three top-level XML elements:

<iq/> (info/query)

Each of these elements can contain additional attributes and namespace definitions that are part of the Jabber protocol. Jabber sessions are maintained through the exchange of XML streams, one from the client to the server, and one from the server to the client. All <message/>, <presence/>, and <iq/> elements are sent within the context of these XML streams. Here is an example from the Jabber specification:

(XML for user session goes here) *

The Jabber protocol is designed to facilitate writing Jabber client code and conducting tests. Details on Jabber can be found at http://www.jabber.com. There you can download an applet that enables you to register with a Jabber server, as seen in Figure 3.6.

Figure 3.6 A Jabber client from http://www.jabber.com.

The Jabber architecture resembles email. A Jabber client is connected to a Jabber server. Like an email server, the Jabber server is responsible for the delivery and receipt of the client's messages. However, Jabber servers will attempt to deliver the messages immediately, thereby supporting instant messaging and conversational capabilities. The Jabber server will queue messages when a peer is unavailable or offline.

The peer-to-peer comparisons of Jabber are more appropriately realized with the relationship between Jabber servers. Every Jabber server is a peer to every other Jabber server. Jabber servers use a number of mechanisms to improve the integrity and security of the system. For instance, hostname dialback independently contacts the sending server to validate incoming data to prevent spoofing.

There are a number of Jabber clients available. Examples include the following:

You can find a list of public servers and their current status at http://www.jabberview.com/. For more information, visit http://www.jabber.org.

  • + Share This
  • 🔖 Save To Your Account