// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.io.*;
import java.net.*;

public class Client3 {
    public static void main(String[] args) throws Exception {
        Socket s = new Socket("localhost", 9999);
        DataInputStream is = new DataInputStream(s.getInputStream());
        save("C:\\z1copy.zip", is);
        save("C:\\z2copy.zip", is);
        save("C:\\z3copy.zip", is);
        is.close();
    }
    public static void save(String filename, DataInputStream is) throws Exception {
        int totsize = is.readInt();
        OutputStream os = new FileOutputStream(filename);
        byte[] b = new byte[10000];
        int n;
        int size = 0;
        while(size < totsize) {
            n = is.read(b, 0, Math.min(b.length, totsize - size));
            os.write(b, 0, n);
            size += n;
        }
        os.close();
    }
}
