Question:
Am implementing a network simulation program that
requires a sender and receiver thread, with a frame object being passed between the two threads.
Could you suggest a way of connecting the threads by means of an object stream that would allow the object to be passed between the two threads.
What is required is much like the pipe implementation in c except from what I gather in java the data types that can be sent are limited.
Answer:
If you feel the best way to implement your
simulation is by using streams, you will want
to look at java.io.PipedInputStream and
java.io.PipedOutputStream. These allow you to
read and write data between two threads. All
you have to do is wrap them with
ObjectInputStream and ObjectOutputStream and
also make your network frame object implement
the Serializable interface, so that it may
be written to an ObjectInputStream.
There may be alternative ways to implement
your simulation by using explicit synchronization
and variable assignments rather than using
streams to simulate the sending and receiving
of frames.