Busy Developers Guide
to the
P2P Sockets Project
Summary
A quick intro for busy developers on what the
P2P Sockets Project is, its benefits, and how to use peer-to-peer
software that has already been ported to work on it, such as a web
server (Jetty), a servlet/JSP engine (Jetty/Jasper), an XML-RPC client
and server (Apache XML-RPC), and more
Questions? Comments?
See the P2P Sockets Homepage
or contact Brad Neuberg at bkn3@columbia.edu. Feel free to call
him at 1-510-938-3263 (Pacific Standard Time, San Francisco) Monday
through Friday, not including weekends. Also see
his weblog, www.codinginparadise.org,
for Mozilla, Java, Jxta, and P2P news.
What is the P2P Sockets Project?
Are you interested in:
- returning the end-to-end principle to the Internet?
- an alternative peer-to-peer domain name system that bypasses
ICANN and Verisign, is completely decentralized, and responds to updates
much quicker than standard DNS?
- an Internet where everyone can create and consume network
services, even if they have a dynamic IP address or no IP address, are
behind a Network Address Translation (NAT) device, or blocked by an
ISP's firewall?
- a web where every peer can automatically start a web server, host
an XML-RPC service, and more and quickly make these available to other
peers?
- easily adding peer-to-peer functionality to your Java socket and
server socket applications?
- having your servlets and Java Server Pages work on a peer-to-peer
network for increased reliability, easier maintenence, and exciting new
end-user functionality?
- playing with a cool technology?
If you answered yes to any of the above, then welcome to the
Peer-to-Peer Sockets project! The P2P Sockets project rebuilds
Java's java.net classes to work on the Jxta peer-to-peer network.1.
While standard TCP/IP sockets and server-sockets are
theoretically peer-to-peer, in practice they are not due to
firewalls, Network Address Translation (NAT) devices, and political and
technical issues with the Domain Name System (DNS)2.
The P2P Sockets project can automatically include these machines
that are usually unreachable, and includes a simple, light-weight
distributed domain name system that can be extended into interesting
new directions for your applications.
The P2P Sockets project already includes a large amount of software
ported to use the peer-to-peer network, including a web server (Jetty)
that can receive requests and serve content over the peer-to-peer
network; a servlet and JSP engine (Jetty and Jasper) that allows
existing servlets and JSPs to serve P2P clients; an XML-RPC client and
server (Apache XML-RPC) for accessing and exposing P2P XML-RPC
endpoints; an HTTP/1.1 client (Apache Commons HTTP-Client) that can
access P2P web servers; a gateway (Smart Cache) to make it possible for
existing browsers to access P2P web sites; and a WikiWiki (JSPWiki)
that can be used to host WikiWikis on your local machine that other
peers can access and edit through the P2P network. Even better, all of
this software works and looks exactly as it did before being ported.
The P2P Sockets abstraction is so strong that porting each of
these pieces of software took as little as 30 minutes to several hours.
Everything included in the P2P sockets project is open-source,
mostly under BSD-type licenses, and cross-platform due to being written
in Java.
This tutorial explains how to create XML-RPC servers that expose their
functions over a peer-to-peer network, and XML-RPC clients that access
this functionality over the peer network. Why would you want to do
this? First, XML-RPC servers can be run on machines that would
ordinarily not be resolvable or reachable, due to the issues discussed
above. Second, you can now leverage your existing XML-RPC skills
to create peer-to-peer networks without learning a new API. Peers
in your network can assume the roles of both XML-RPC client and server,
interacting with other peers who are themselves both XML-RPC clients and
servers. The XML-RPC functions exposed could be related to
instant messaging, blogging using the MetaWeblog XML-RPC API, editing
WikiWikis using the WikiWiki XML-RPC API, and more. Now every
peer in the network, regardless of whether their cable ISP treats them
as second-class citizens, can easily be both a writeable and readable
node, opening the possibility of a Two Way Web. Even better,
everything is built above a modified version of Jetty, an open-source
web server that is specifically designed to be small and embeddable in
other applications, making it easy for you to roll P2P functionality
into your own applications.
For more information on using the raw P2P sockets and server sockets in
your own code, and for details information on how the peer network
itself is created, see the tutorial Introduction
to Peer-to-Peer Sockets. For information on creating P2P web
servers, servlets, JSPs, and Web Application Archives (WARs), see the
tutorial How
to Create Peer-to-Peer Web Servers, Servlets, and JSPs.
Requirements and Configuration
You must download and install the following software to
develop and work with P2P Sockets:
- JDK
1.4+ - P2P Sockets only works with versions of the JDK after 1.4
because P2P Sockets subclasses java.net.InetAddress. Prior to 1.4
this class was marked final and
could not be subclassed. The JDK is needed if you want to use
JSPs; otherwise the Java Runtime Environment (JRE) can be used instead.
- Ant 1.5.3+ - Used
to both build and run P2P Sockets and extensions such as Jetty and Jasper
- P2PSockets-1.0-beta1.zip
- The latest release of the P2P Sockets package.
Install and configure the JDK and Ant, and make sure both are in your
path so they can be run from the command-line. Unzip the
P2PSockets zip file into the top-level of your hard-drive; spaces are
not allowed in the directory names, or the P2P Sockets build files will
not work correctly.
The P2P Sockets directory already includes two different directories, test/clientpeer and test/serverpeer, that have Jxta
configuration information already set up (these are in the hidden
directories test/clientpeer/.jxta
and test/serverpeer/.jxta,
respectively). If you want to learn more about how to configure
Jxta, read about the Jxta
Configurator. The two test peers have already been configured
for the worst possible case, which is that you are behind a firewall and
a NAT device, which means you must use other intermediate peers to relay
your requests; this configuration will work even if you are not under
these conditions. One of the nice aspects about Jxta, though, is
that this will all be transparent and hidden from you as you program and
use the system.
When testing the examples in this tutorial, you must be connected to
the Internet. This is for two reasons; first, the examples use a
public Jxta server Sun has set up that helps bootstrap peers into the
Jxta network; and second, on some operating systems, such as on Windows
XP by default, the network subsystem shuts down if you are not connected
to the Internet, preventing client peers and server peers that are
running on the same machine from finding or communicating with each
other.
Creating a P2P Server Socket
(mostly source code of creating a P2P server socket,
with a quick intro to initializing the network using a string; pointers
for info. provides ant command to start example)
Creating a P2P Client Socket
(mostly source code of creating a P2P client socket; pointers
for more info; provides ant command to start example)
Creating a P2P Web Server
(simply shows how to use start.jar, with pointers for more
info if you want to drop it into your app. provides ant command to start
example)
Accessing P2P Web Sites from a Normal Browser
(Says how to start the P2PWebProxy, tells you to configure
your web-browser to use the proxy but doesn't tell you how, then tells
you to type the address into your location bar).
Creating P2P Servlets, JSPs, Web Application Archives (WARs),
and XML-RPC Clients and Servers
(very short; simply says that no changes need to be made;
just put them in the right directories in Jetty. provides ant command to
start example)
Limitations and Security Concerns
text
Resources
About the Author
Brad
"GNUberg" Neuberg is an open-source developer living in San
Francisco. He is currently involved with the BlackConnect project, an
effort to allow programmers to write Mozilla XPCOM components in Java;
the Java-Mozilla Integration
project, an umbrella effort for open-source developers to work on
turning Java into a full-fledged member of the Mozilla platform; the P2P Sockets project, an
initiative to port the existing web onto a peer-to-peer foundation and
make working with Jxta easier; the Paper Airplane project, a browser
plugin that empowers everone to be a writer as well as a reader; and
submissions to the Jxta and Mozilla projects. In the past
he has worked on the OpenPortal project and the Flash/Java Integration
project. He is an avid Java, C++, JavaScript, and Mozilla Platform
hacker who is a strong believer in usability. He has a B.A. in
Computer Science from Columbia University and experience building
enterprise trading systems for the securities industry using J2EE
technologies. He is now slightly older than he was when the
picture on the left was taken. Occasionally, after enough beers,
he'll start tap dancing.
This work is licensed under the
Creative Commons Attribution-NonCommercial License by Bradley Keith
Neuberg. To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc/1.0/ or send a letter to
Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.