// 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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class AdvancedClient {
    public static void main(String[] args) throws IOException, InterruptedException {
        List<MultiSocket.Destination> dest = new ArrayList<MultiSocket.Destination>();
        dest.add(new MultiSocket.Destination("localhost", 12345));
        dest.add(new MultiSocket.Destination("localhost", 12346));
        Socket s = new MultiSocket(dest);
        OutputStream os = s.getOutputStream();
        InputStream is = s.getInputStream();
        int b;
        os.write(1);
        b = is.read();
        System.out.println(b);
        Thread.sleep(6000);
        os.write(2);
        b = is.read();
        System.out.println(b);
        Thread.sleep(6000);
        os.write(3);
        b = is.read();
        System.out.println(b);
        Thread.sleep(6000);
        os.write(4);
        b = is.read();
        System.out.println(b);
        os.close();
        is.close();
        s.close();
    }
}
