import java.io.*;
import java.net.*;
import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class freceive extends JFrame{
JTextField messageField;
public static void main(String args[]) throws IOException{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter host address: ");
String ip = in.readLine();
Socket theServer;
DataInputStream sIn;
BufferedReader sInPrint;
try {
theServer = new Socket(ip, 45654);
sIn = new DataInputStream(theServer.getInputStream());
sInPrint = new BufferedReader(new InputStreamReader(
theServer.getInputStream()));
}
catch(UnknownHostException xe){
System.out.println("Could not find host.");
return;
}
catch(IOException e){
System.out.println("Error getting I/O from server.");
return;
}
String file = sInPrint.readLine();
int index;
if((index=file.lastIndexOf('\\'))!=-1);
else if((index=file.lastIndexOf('/'))!=-1);
file = file.substring(index+1);
FileOutputStream fOut = new FileOutputStream(file);
System.out.println("Receiving "+file+"...");
byte[] data = new byte[512];
int read;
int total = 0;
freceive thereceiver = (new freceive());
thereceiver.show();
while((read=sIn.read(data))!=-1){
total += read;
fOut.write(data,0,read);
thereceiver.messageField.setText(total+" bytes received.");
}
System.out.println("Successfully received "+total+" bytes.");
System.exit(0);
}
public freceive(){
this.setSize(200,50);
messageField = new JTextField("",50);
this.getContentPane().add(messageField, java.awt.BorderLayout.NORTH);
}
}