?? search.java
字號:
package edu.uiuc.cs.cs327.linuxwifi.services;
import java.io.*;
import java.util.*;
import java.net.URL;
import net.jxta.peergroup.PeerGroup;
import net.jxta.peergroup.PeerGroupFactory;
import net.jxta.exception.PeerGroupException;
import net.jxta.document.AdvertisementFactory;
import net.jxta.document.MimeMediaType;
import net.jxta.socket.JxtaServerSocket;
import net.jxta.protocol.PipeAdvertisement;
import net.jxta.protocol.PeerAdvertisement;
import net.jxta.id.IDFactory;
import edu.uiuc.cs.cs327.linuxwifi.app.AppAPI;
import net.jxta.socket.JxtaSocket;
/**
* this application creates an instance of an input pipe,
* and waits for msgs on the input pipe
*
*/
public class Search {
Vector availablePeerVector;
PeerAdvertisement peer = null;
PipeAdvertisement pipe = null;
Vector pipeVector = new Vector();
JxtaSocketLinuxwifi socEx = null;
SearchRequest srchRequest;
/**
* main
*
* @param args command line args
*/
public Search(MusicProfile mp, PeerGroup pg, AppAPI app, Vector peers) {
availablePeerVector = peers;
srchRequest = new SearchRequest(mp);
if(availablePeerVector.size()>0){
for(int i=0;i<availablePeerVector.size();i++){
// Get the next peer to send a search request to
NodeObject no = (NodeObject) availablePeerVector.get(i);
peer = (PeerAdvertisement) no.getPeerAdvertisement();
System.out.println ("Peer Name: " + peer.getName());
try {
FileInputStream is = new FileInputStream(".jxta//socket.adv");
//CREATE a new pipeID for the peer the request will be sent to
pipe = (PipeAdvertisement) AdvertisementFactory.newAdvertisement(MimeMediaType.XMLUTF8, is);
String pipeIDString = peer.getPeerID().toString(); //sets peer ID to pipe ID
pipeIDString = pipeIDString.substring(0, pipeIDString.length()-2).concat("04");//Correctly formats Pipe ID
URL peerURL = new URL(pipeIDString);
pipe.setPipeID(IDFactory.fromURL(peerURL));//Changes the pipe ID on our pipe advertisement
is.close();
// if(MainGUI.DEBUG) System.out.println("Creating pipe advertisement");
// if(MainGUI.DEBUG) String pipeIDString = peer.getPeerID().toString(); //sets peer ID to pipe ID
// if(MainGUI.DEBUG) System.out.println(pipe.getID().toString());//FOR DEBUG
// Create a new socket to send the search request over
socEx = new JxtaSocketLinuxwifi(srchRequest, pipe, pg, app);
System.out.println("Closed input stream");
// Send out the search reqeuest
System.out.println("Starting socket");
socEx.start();
System.out.println("Started socket done");
} catch (Exception e) {
System.out.println("failed to read/parse pipe advertisement");
e.printStackTrace();
System.exit(-1);
}//end try
}//end of for loop
}//end if
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -