Why NetworkStream ( Newbie )

  • Thread starter Thread starter Fernando
  • Start date Start date
F

Fernando

Why does the NetworkStream class exist at all if you can read/write through
a Socket instance ? What is the advantage ?there must be one, i just didnt
grasp it yet :)

bye.
 
Well, one possible use is polimorphism with other streams, like FileStream ?

Sorry, i dont come from Java background but from C++ and i have seen only
one implementation of a socket stream in the STL style, but never used it
( or know anyone who did )

bye again.
 
Thanks peter.

bye.

Peter Duniho said:
The most obvious reason is that NetworkStream inherits Stream, which means
you can hook your network i/o object to any input or output that can use a
Stream. By abstracting the Socket class to a Stream class, you can then
use the Socket with a wide variety of classes that need to know nothing
about Socket.

There are some subtle differences in the semantics between Socket and
Stream as well, but IMHO the above abstraction issue is the major reason
for it existing. It's very convenient.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top