// Make two pairs of connected piped streams
PipedInputStream pinc = null;
PipedInputStream pins = null;
PipedOutputStream poutc = null;
PipedOutputStream pouts = null;
try {
pinc = new PipedInputStream();
pins = new PipedInputStream();
poutc = new PipedOutputStream(pins);
pouts = new PipedOutputStream(pinc);
}
catch (IOException e) {
System.out.println("PipedStreamExample: Failed to build piped streams.");
System.exit(1);
}
// Make the client and server threads, connected by the streams
PipedClient pc = new PipedClient(pinc, poutc);
PipedServer ps = new PipedServer(pins, pouts);
// Start the threads
System.out.println("Starting server...");
ps.start();
System.out.println("Starting client...");
pc.start();
// Wait for threads to end
try {
ps.join();
pc.join();
}
catch (InterruptedException e) {}
System.exit(0);