Why is the receiver thread not receiving anything in my Java piped streaming program? : <p>I have 3 very small classes.</p>

<p>The main class:</p>

<pre><code>import java.io.*;

public class ConnectionManager {
    public static void main(String argv[]) {

        try {
            PipedOutputStream pout = new PipedOutputStream();
            PipedInputStream pin = new PipedInputStream(pout);

            Sender s = new Sender(pout, true);
            Receiver r = new Receiver(pin, true);
            System.out.println("Starting threads");
            s.start();
            r.start();
        } catch (Exception e) {}
    }
}
</code></pre>

<p>The Sender class</p>

<pre><code>import java.io.*;
import java.util.Random;

public class Sender extends Thread {
    ObjectOutputStream oos;
    boolean primitive;

    public Sender(OutputStream os, boolean primitive) {
        try {
            oos = new ObjectOutputStream(os);
        } catch (Exception e) {}
        this.primitive = primitive;
    }

    public void run() {
        Random rand = new Random();
        while (true) {
            try {
                System.out.println("Integer is being sent");
                oos.writeInt(10);
                Thread.sleep(1000);
            } catch (Exception e) {}
        }
    }
}
</code></pre>

<p>And the Receiver class</p>

<pre><code>import java.io.*;

public class Receiver extends Thread {
    ObjectInputStream ois;
    boolean primitive;

    public Receiver(InputStream is, boolean primitive) {
        try {
            ois = new ObjectInputStream(is);
        } catch (Exception e) {}
        this.primitive = primitive;
    }

    public void run() {
        System.out.println("Receiver is starting");
        while (true) {
            try {
                int x = ois.readInt();
                System.out.print("An int was read: " + x);
            } catch (Exception e) {}
        }
    }
}
</code></pre>

<p>Please ignore seemingly unused variables like <code>primitive</code> and <code>rand</code>. They're holdovers from slightly different versions that I was testing out earlier and I was too lazy to remove them.</p>

<p>Anyway, when I run the main method in <code>ConnectionManager</code>, I get this as output:</p>

<pre><code>Starting threads
Receiver is starting
Integer is being sent
Integer is being sent
Integer is being sent
Integer is being sent
Integer is being sent
Integer is being sent
Integer is being sent
Integer is being sent
//... ad infinitum 
</code></pre>

<p>Why is the receiver thread not getting the messages that are piped through? What am I missing here?</p>
