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

public class SendAgent {
   public static void main(String args[]) 
   throws Exception {
      if(args.length != 4) {
         System.out.println("usage: SendAgent <agent> <host> <port> <agent-name>");
         System.exit(0);
      }
      FileInputStream fin = new FileInputStream(args[0]);
      Socket sock = new Socket(args[1],Integer.parseInt(args[2]));
      OutputStream out = sock.getOutputStream();
      ObjectOutputStream oout = new ObjectOutputStream(out);
      oout.writeObject(args[3]);
      File file = new File(args[0]);
      long length = file.length();
      byte buffer[] = new byte [ (int)length ];
      int ch;
      int i = 0;
      while((ch = fin.read()) != -1) {
         buffer[i] = (byte)ch;
         i++;
      }
      oout.writeObject(buffer); 
      oout.flush();
      oout.close();
      sock.close();
   }
}
