import java.net.InetAddress;
import java.net.*;
import java.io.BufferedInputStream;
import java.io.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007-2011</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Main {
    private InetAddress destIP = null;
    private int destPort = 1024;
    private InetSocketAddress destSocketAddress = null;
    private Socket clientSocket = null;
    private BufferedOutputStream TCPIPoutputStream = null;
    private long totalTxBytes = 0;
    private long lastTotalTxBytes = 0;
    byte[] inBuf = new byte[4096];
    byte[] outBuf = new byte[4096];
       public Main() {
        // open input file
        FileInputStream fileIn = null;
        try {
        	fileIn = new FileInputStream("PRBS11_1bw_200MB.bin");
        } catch (FileNotFoundException ex1) {
        	System.err.println("could not find input file");
        	System.exit(0);  // no point in continuing.
        }

        
        try {
            destIP = InetAddress.getByAddress(new byte[] {(byte) 172, 16, 1,
                                              (byte) 128});
            destSocketAddress = new InetSocketAddress(destIP, destPort);
            clientSocket = new Socket();
            clientSocket.connect(destSocketAddress, 1000); // blocking

            TCPIPoutputStream = new BufferedOutputStream(clientSocket.getOutputStream(), 4096);
            
            while (true) {
            	int n1 = fileIn.read(inBuf);
            	if(n1 > 0){
            		TCPIPoutputStream.write(inBuf, 0, n1);
            		totalTxBytes += n1;
//            		if((totalTxBytes - lastTotalTxBytes ) > 100000){
//            			System.out.println(totalTxBytes);
//            			lastTotalTxBytes = totalTxBytes;
//            			
//            		}
                } else {
                	break; // reached the end of the tx file
                }
            }
        } catch (UnknownHostException ex) {
        } catch (IOException ex) {
        }
        try {
            fileIn.close();
             TCPIPoutputStream.close();
            clientSocket.close();
        } catch (IOException ex2) {
        }

    }

    public static void main(String[] args) {
        Main main = new Main();
    }
}
