tags:

views:

99

answers:

3

Hi,

I have a producer which provides a System.IO.Stream instance. I also have several clients which consume this stream.

Is it possible to give each client a "private view" of the stream? For example, if clientA reads from the stream, it doesn't affect the position clientB sees (i.e. if clientB start reading from the stream, it gets the beginning of it, not from where clientA left the position). If it makes any difference, the clients are only reading from the stream.

Hope it makes sense.

Thanks in advance, Mike

+1  A: 

You could inherit a class from Stream that takes the underlying stream in the constructor and keeps track of the position of that instance of private view. This works only if the base stream is seekable.

Mehrdad Afshari
A: 

You can do this by reading the stream, caching the data and opening new streams to the cache for each client.

gabor
+1  A: 

I think you'll need to create your own custom "TssStream" which handles the buffering from the source stream to multiple streams.

The number of methods you'll need to override from Stream is limited to handle read only, but coordinating where each client (likely via a helper) will require a little thought.

Richard