⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagehandler.java

📁 We intend to develop a wifi enabled p2p file sharing system on a linux platform using jxta and java.
💻 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;

/**
 * this application creates an instance of an input pipe,
 * and waits for msgs on the input pipe
 *
 */

public class MessageHandler {

    /**
       *  main
       *
       * @param  args  command line args
       */
    
    public MessageHandler(PeerGroup pg, AppAPI app) {
        Vector availablePeerVector = new Vector();
        PeerAdvertisement peer = null;
        PipeAdvertisement pipe = null;
        Vector pipeVector = new Vector();
        JxtaServerSocketLinuxwifi socEx = new JxtaServerSocketLinuxwifi(app);

        
System.out.println("MSG Handler: Created objects");        
            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 = pg.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
                System.out.println(pipe.getID().toString());//FOR DEBUG
                             
                //Send static netPeerGroup object to socket
                socEx.setnetPeerGroup(pg);
                
                //Send pipe advertisment to the socket
                socEx.setpipeAdv(pipe);
                is.close();
                socEx.setserverSocket( new JxtaServerSocket(socEx.getnetPeerGroup(), socEx.getpipeAdv()) );

                // we want to block until a connection is established
                socEx.getserverSocket().setSoTimeout(0);
        } catch (Exception e) {
                System.out.println("failed to read/parse pipe advertisement");
                e.printStackTrace();
        }//end catch
            
        //MusicProfile searchProfile = new MusicProfile ("Pearl Jam","Daughter","Unknown");
        socEx.start();
    }
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -