Skip to main content

JXTA P2P application that showcases both peer consuming and supplying

4 replies [Last post]
Joined: 2007-07-28


I am now engaging in JXTA study and preparing to code up some samples from the JXTA Programmers Guide... but I am confused with the examples in the guide.

If JXTA is P2P and I want my P2P "Peer" applications to both "supply" data (say files for file sharing) and "consume" data why do i see all the examples in the latest 2.5 June 2007 Programmers Guide as and

This looks like client-server. How come I do not see examples such as which perhaps the "Peer" (playing both the role of client and server) has for example two private class declarations (one for the client role and one for the server role) like this:

// This class is the "Peer" that plays the role of client (consumer) and server (supplier) independently (see extends
// Thread)

class Peer

// Public methods omitted for simplicity of example

private class PeerClient extends Thread
public void run ()
{ // Consumption of data here }

private class PeerServer extends Thread
public void run ()
{ // Supply data here }


The examples in the guide imply client-server even though I know JXTA is a P2P protocol framework. But stylistically I am confused. Am I interpreting the and apps incorrectly? If I need to create a P2P "Peer" or "Member" if you will, how can I construct this class with the capability of both supplying and consuming at anytime with listeners available to tell the peer when data has arrived from another peer?

Your expertise and insight would be extremely useful as I forge ahead with a demo at my work on how to develop a consuming and supplying peer for a distributed content application.

I have used OMG Standard DDS (Data Distribution Service) which is also P2P based but even though it is a standard it is complicated but supplies the up front idea that a DDS app can be either a consumer (subscriber), supplier (publisher) or both (a true give and take peer of resources (data)).

Any sample code that anyone on this board can contribute in how I see an example "Peer" app be both a "consumer" and "supplier" of resources (files) ? ...Because the JXTA 2.5 Programmers Guide has examples that showcase exclusive clients or servers.


Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-04-07


I hope this article can help you play the peer with both role of a server and a client.

Best day.


Joined: 2003-06-12

The examples illustrate the client and server functionality, they are meant to provide some guidance to traditional client/server programming, it does not preclude a node from acting in both capacities.

Joined: 2007-07-28

Yes, but I would like to see (in code) the setup of how to establish a "Peer" (say instead of two files and that would demonstrate how to:

1) Supply file data to other peers that want to be "up-to-date" with the supplying peer(s).
2) Consume file data from other peer(s)
3) Show in the consumer some sort of event listener to tell it that it has received the data

I simply would build the "Peer" ( code into a jar (along with other application .java files) that I would simply install on any workstation that wants to be a peer and have the ability (like described above) to both independently supply and consume services (in this case files/file data).

Joined: 2007-06-14

Hi there,

I don't think you're going to be able to find an example of what you're looking for in the tutorials. They're meant to be general examples. While what you're looking for IS indeed possible and not too difficult in jxta, it is quite specific.

You really have two options:
Use the examples to learn how to set up a client/server system on your peer and work out how to do the updating, consuming and event management yourself. (The more fun option in my opinion)
take a look at one of the many open source projects listed on the jxta website and see if you can find one that matches your needs and take a look at their source code.

good luck ;)