Chapter 5. The Pipe API
In this chapter, we’ll expand on our restaurant auction example from Chapter 4 to show how the RestoPeer and HungryPeer communicate with each other once they have each discovered and joined the RestoNet peergroup. From a functional point of view, this communication is the basis for what the distributed application does; communication between the peers enables the RestoPeer to offer services and the Hungry Peer to place bids on those services.
From a programming point of view, this communication is possible due to the Java API binding that JXTA provides for pipes. Pipes are the fundamental construct of JXTA that allow peers to communicate with each other; a peer that wants to offer a service creates and advertises a pipe to the JXTA peergroup. A peer that wants to use a service discovers pipe advertisements in a peergroup and makes a connection to the service via the pipe.
Once again, we’ll show only the Java language binding for JXTA pipes in this chapter. Because JXTA defines the protocol by which pipes are advertised and used, any JXTA peer can communicate with any other JXTA peer over the pipe; the two peers do not need to be programmed in the same language.
Creating Pipes
We’ll illustrate the use of pipes by modifying our previous auctioning example; we will add a set of pipes to allow HungryPeers and RestoPeers to communicate within the RestoNet peergroup. Since pipes are unidirectional, we need two pipes for a HungryPeer and RestoPeer to exchange ...
Get JXTA in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.