tags:

views:

380

answers:

3

I wanted to know how streams work internally in c#. Does StreamReader and StreamWriter use recv() and send() functions of Winsock internally. I also wanted to know the difference between streams and channels.

A: 

I'd bet they don't use winsock internally, because streams aren't only used for network IO - they're used for lots of things (moving chunks of memory, loading files, etc)

edit - i've never heard of a c# channel, and google doesn't bring anything up?

Chris
+2  A: 

I think you are a bit confused. A StreamReader is not a Stream, nor is a StreamWriter. Stream doesn't know anything about network I/O as it's abstracted further out.

NetworkStream is a stream that knows how to talk on a network, but StreamReader and StreamWriter work with abstract Stream references (or rather more abstract).

NetworkStream uses a Socket class, which underneath everything else does in fact call Winsock API's, but you don't really need to know anything about that to use it.

There's nothing called a "channel", perhaps you could be more specific.

Mystere Man
And Socket is more likely to use ReadFile/WriteFile as these allow the use of asynchronous operations and IO Completion ports -- which underly all of .NET's async-IO.
Richard
A: 

Channels are referenced throughout the Windows Communication Foundation (available in .NET 3.0).

Streams and channels are not directly related. You should reference Windows Communication Foundation documentation found on MSDN. MSDN WCF

Another great resource is Indigo Girl and gang at IDesign.NET.

Don't forget security. WCFSecurity