www.pudn.com > FileShare.rar > ReceiveDownloadFileInfo_thread.java


/* 
 * ReceiveDownloadFileInfo_thread.java 
 * 
 * Created on 2008年4月25日, 下午8:52 
 * 
 * To change this template, choose Tools | Template Manager 
 * and open the template in the editor. 
 */ 
 
/** 
 * 
 * @author 602 
 */ 
import java.io.*; 
import java.net.*; 
 
public class ReceiveDownloadFileInfo_thread extends Thread 
{ 
    /** Creates a new instance of ReceiveDownloadFileInfo_thread */ 
    DataOutputStream out=null; 
    DataInputStream in=null; 
    ServerSocket serverListen=null; 
    Socket client=null; 
     
    String downloadFileName=""; 
    String downloadFilePath=""; 
     
    public ReceiveDownloadFileInfo_thread()  
    { 
    } 
     
    public void run() 
    { 
        while(true) 
        { 
            try 
            {             
                serverListen=new ServerSocket(7000);//7000端口传输选中下载文件的信息     
            } 
            catch(IOException e1) 
            { 
                System.out.println("正在监听下载信息"); 
            } 
 
            try 
            { 
                client=serverListen.accept(); 
                 
            } 
            catch(IOException e2) 
            { 
                 System.out.println("正在等待下载连接"); 
            } 
 
            try 
            {  
                in=new DataInputStream(client.getInputStream()); 
                out=new DataOutputStream(client.getOutputStream()); 
            } 
            catch(IOException e) 
            {} 
             
            try 
            { 
                String fileInfo=in.readUTF(); 
                int index=fileInfo.lastIndexOf("\\"); 
                downloadFileName=fileInfo.substring(index+1,fileInfo.length()); 
                downloadFilePath=fileInfo.substring(0,index+1); 
 
                out.close(); 
                in.close(); 
                serverListen.close(); 
                client.close(); 
            } 
            catch(IOException e) 
            {} 
             
            try 
            { 
                 SendDownloadFile_thread sendDownloadThread=new SendDownloadFile_thread(downloadFilePath,downloadFileName); 
            sendDownloadThread.start(); 
            } 
            catch(IllegalThreadStateException e) 
            {System.out.print("start 错误");} 
            
             
        } 
    } 
    public String getDownloadFileName() 
    { 
        return downloadFileName; 
    } 
    public String getDownloadFilePath() 
    { 
        return downloadFilePath; 
    } 
}