JXTA Java
™
Standard Edition v2.5:
Programmers Guide
September 10
th
, 2007
JXSE 2.5 Programmers Guide : 1
© 2002-2007 Sun Microsystems, Inc. All rights reserved.
Sun, Sun Microsystems, the Sun Logo, and Java are trademarks, registered trademarks, or service marks of Sun Microsystems,
Inc. in the United States and other countries.
All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc., in the
United States and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun
Microsystems, Inc.
UNIX is a registered trademark in the United States and other countries, exclusively licensed through X/Open Company, Ltd.
Please Recycle
JXSE 2.5 Programmers Guide : 2
Table of Contents
Introduction................................................................................................7
Why JXTA™ ?...........................................................................................7
What is JXTA™ Technology?....................................................................8
What can be done with JXTA™ Technology? ..........................................8
Where to get JXTA™ technology.............................................................9
Getting Involved......................................................................................9
JXTA™ Architecture..................................................................................10
Overview...............................................................................................10
JXTA Components..................................................................................11
Key Aspects of the JXTA Architecture...................................................11
JXTA Concepts...........................................................................................12
Peers......................................................................................................12
Peer Groups...........................................................................................12
Network Services..................................................................................13
Peer Group Services..............................................................................13
Messages...............................................................................................15
Pipes......................................................................................................16
JxtaSocket and JxtaBiDiPipe.................................................................17
Advertisements......................................................................................19
Security.................................................................................................20
IDs.........................................................................................................21
Network Architecture...............................................................................22
Network Organization...........................................................................22
Shared Resource Distributed Index (SRDI)..........................................23
Queries..............................................................................................23
Firewalls and NAT.................................................................................26
JXTA Protocols...........................................................................................27
Peer Discovery Protocol........................................................................28
Peer Information Protocol.....................................................................28
Peer Resolver Protocol..........................................................................28
Pipe Binding Protocol............................................................................29
Endpoint Routing Protocol....................................................................29
Rendezvous Protocol.............................................................................30
The Basics.................................................................................................31
Getting Started......................................................................................31
Accessing On-line Documentation .......................................................31
Downloading Binaries...........................................................................31
Downloading Binaries...........................................................................31
Compiling JXTA Code............................................................................31
Running JXTA Applications...................................................................32
"Public JXTA Network" Configuration Setting......................................33
JXTA and HTTP Proxies ....................................................................33
JXSE 2.5 Programmers Guide : 3
Do I need a Proxy? ............................................................................33
Creating various ID types.....................................................................34
ID Tutorial source code.....................................................................35
Advertisements......................................................................................38
Advertisement Tutorial source..........................................................39
Messages and Message Elements.........................................................47
Design points for JXTA Messages......................................................47
Design points for Message Elements................................................48
Message and Message Element tutorial source................................49
Programming with JXTA...........................................................................56
HelloWorld Example..........................................................................56
Running the HelloWorld Example.....................................................56
Source Code: HelloWorld..................................................................57
Working with Local Configuration Example......................................58
Running the WorkingWithLocalConfiguration Example....................58
Pitfalls................................................................................................58
Source Code: WorkingWithLocalConfiguration................................59
Peer Discovery..........................................................................................62
Discovery Service..................................................................................62
DiscoveryClient.....................................................................................63
Source Code: DiscoveryClient...............................................................65
Source Code: DiscoveryServer..............................................................68
Membership Service.................................................................................71
Role of the Membership Service...........................................................71
Membership Service and Credentials...................................................71
Local Credentials and Remote Credentials...........................................71
Membership Services and Peer Groups................................................71
Membership Service and Other Services..............................................71
Membership Service Basic Operation ..................................................72
Remote Credentials & Access Control..................................................75
PSE Membership Service.........................................................................77
Introduction...........................................................................................77
The PSE Membership Service and Other Services...............................77
The PSE Membership Service and Keystores.......................................77
Accessing the PSE Membership Service...............................................77
PSE Membership Service Components.................................................77
PSE Membership First Steps................................................................77
The PSE Credential...............................................................................78
PSE Config............................................................................................78
Pipe Service..............................................................................................81
JXTA Pipe Service..................................................................................81
PipeServer.............................................................................................82
Source Code: PipeClient.......................................................................84
Source Code: PipeServer......................................................................86
Multicast Socket.......................................................................................90
Description............................................................................................90
JXSE 2.5 Programmers Guide : 4
Learning goals.......................................................................................90
Basic Operations...................................................................................90
Caveats..................................................................................................90
Source Code : JxtaMulticastSocketClient.............................................91
Source Code : JxtaMulticastSocketServer............................................93
Propagated Pipe Example.........................................................................95
PropagatedPipeClient...........................................................................95
Source Code: PropagatedPipeClient.....................................................97
Source Code : PropagatedPipeServer.................................................100
JxtaBiDiPipe Example.............................................................................105
JxtaBiDiPipe........................................................................................105
JxtaServerPipeExample.......................................................................106
Source Code: JxtaServerPipeExample................................................107
JxtaBidiPipeExample...........................................................................112
Source Code: JxtaBidiPipeExample.....................................................113
JxtaSocket Tutorial.................................................................................116
JxtaServerSocketExample...................................................................117
Source Code: SocketServer................................................................118
Pipe adertisement example.................................................................121
ClientSocket........................................................................................122
Source Code: SocketClient.................................................................123
JXTA Services..........................................................................................126
Creating a JXTA Service......................................................................127
Server..................................................................................................129
readMessages()...............................................................................130
Source Code: Service Server..............................................................131
Example Service Advertisement:....................................................135
Service Client......................................................................................136
Source Code: Service Client...............................................................138
Password Protected Peer Group.............................................................141
The constructor method PrivatePeerGroup()..................................142
createPeerGroup()...........................................................................142
createPasswdMembershipPeerGroupModuleImplAdv()..................143
createPeerGroupAdvertisement()....................................................144
discoverPeerGroup()........................................................................145
joinPeerGroup()...............................................................................145
completeAuth()................................................................................145
Source Code: PrivatePeerGroup.........................................................147
Glossary..................................................................................................155
Appendix I: References...........................................................................159
Appendix II: Troubleshooting.................................................................160
Errors compiling JXTA applications....................................................160
Errors running JXTA applications.......................................................160
Setting the classpath variable.........................................................160
Unable to discover JXTA peers........................................................160
Using the JXTA Shell...........................................................................160
JXSE 2.5 Programmers Guide : 5