JXTA & Peer-to-Peer Networks
by Sing Li

Listing One
public static void main(String[] argv) {
    if (argv.length != 1) {
        System.err.println("Usage: DDJFinder proxyServerURL");
        System.exit(1);
    }
       DDJFinder myFinder = new DDJFinder(argv[0]);
       myFinder.init();
       myFinder.processMessages();
}

Listing Two
public void init() {
try {
        System.err.println("Creating peer network...");
        peerNetwork = PeerNetwork.createInstance(serviceName);
        System.err.println("Connecting to " + proxyURL);
        peerNetwork.connect(proxyURL, null);
        }
   catch (Exception ex) {
            System.err.println("Problem connecting to JXTA network...");
                            ex.printStackTrace();
        }
    }
    

Listing Three
public void processMessages()  {
     try {
               System.err.println("Listening to pipe " + IP2P_PIPE_ID);
         peerNetwork.listen(serviceName, IP2P_PIPE_ID, "JxtaPropagate");
         System.err.println("Ready.");
         while(true) {
             Message msg = pollForMsg();
                     if (! isCommand(msg))
                            logSender(msg);
                     else
                         {
                             if (!isTerminate(msg))
                        sendMessage(peerNetwork,processCmd(msg),serviceName);
                              else
                                  break;
                          }
                    }// of while
     } catch (Exception ex) {
         System.err.println("Error during message processing");
         ex.printStackTrace();
         System.exit(1);
     }
    }






1


