Main
Topics
Community
Members
Visitor Number: 9491, Total Hits: 74776.
import java.io.*;
import java.net.*;
public class fsend {
    public static void main(String args[]) throws IOException{
        InetAddress yours = null;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try {
            yours = InetAddress.getLocalHost();
        }
        catch(UnknownHostException e){
            System.out.println("Error finding your IP.");
            return;
        }
        System.out.println("Your IP Address: "+yours.getHostAddress());
        System.out.print("Input file address: ");
        String file = in.readLine();
        FileInputStream fIn = new FileInputStream(file);
        System.out.println("Waiting for a connection...");
        ServerSocket theServer;
        try {
            theServer = new ServerSocket(45654);
        }
        catch(IOException e){
            System.out.println("Error creating server.");
            return;
        }
        Socket receiver;
        try {
            receiver = theServer.accept();
        }
        catch(IOException e){
            System.out.println("Invalid client found");
            return;
        }
        PrintWriter sOutPrint;
        DataOutputStream sOut;
        try {
            sOutPrint = new PrintWriter(receiver.getOutputStream(),true);
            sOut = new DataOutputStream(receiver.getOutputStream());
        }
        catch(IOException e){
            System.out.println("Error getting I/O for client.");
                        return;
        }
        System.out.println("Sending file to client...");
        sOutPrint.println(file);
        byte[] data = new byte[512];
        int read;
        int total = 0;
        while((read=fIn.read(data))!=-1){
            sOut.write(data,0,read);
            total += read;
        }
        in.close();
        theServer.close();
        sOut.close();
        fIn.close();
        sOutPrint.close();
        System.out.println("Successfully sent "+total+" bytes.");
        
    }
}
Display PI Counter   

Contact me at: tralbrecht@gmail.com