package server;

import java.io.*;
import java.net.*;

public class TransFile extends Thread
{
	Socket recSkt;
	Socket sendSkt;
	String filename;
	Server control;
	
	public TransFile( Socket r, Socket s, String name, Server ser )
	{
		recSkt = r;
		sendSkt = s;
		filename = name;
		control = ser;
	}
	
	public void run()
	{
		try{
			BufferedInputStream fileReader =
				new BufferedInputStream( recSkt.getInputStream() );
			PrintStream p = new PrintStream( sendSkt.getOutputStream() ); 
			
//			BufferedOutputStream fileWriter = 
//				new BufferedOutputStream( new FileOutputStream(filename) );
			int read;
			
			while( ( read = fileReader.read() ) != -1 )
			{ 
//	            showText("."); 
	            p.write( read ); 
	        }
			fileReader.close(); 
//	        fileWriter.flush();
//	        fileWriter.close();
	        recSkt.close();
	        p.flush();
	        p.close();
	        sendSkt.close();
	        control.showText( filename + "ÀÉ®×¶Ç°e§¹²¦¡I");
		}
		catch(IOException e) { 
            System.out.println(e.toString()); 
        }
	}

}
