473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Why NetworkStream ( Newbie )

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.
Aug 11 '08 #1
3 1885
On Mon, 11 Aug 2008 15:47:46 -0700, Fernando <Fa************@hotmail.com>
wrote:
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 :)
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
Aug 11 '08 #2
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.

"Fernando" <Fa************@hotmail.comescreveu na mensagem
news:%2****************@TK2MSFTNGP03.phx.gbl...
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.


Aug 11 '08 #3
Thanks peter.

bye.

"Peter Duniho" <Np*********@nnowslpianmk.comescreveu na mensagem
news:op***************@petes-computer.local...
On Mon, 11 Aug 2008 15:47:46 -0700, Fernando <Fa************@hotmail.com>
wrote:
>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 :)

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

Aug 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cmjman | last post by:
I have an issue where networkStream.Write doesn't perform its write downstream from my client program until the network stream is closed. I then see the data that was sent appear on the other side....
1
by: Daniel | last post by:
i would like to konw when the data sent so that i can close the streamwriter and networkstream is there some sort of call backs/events i have to implement for this to work? if so how? can i just...
4
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create...
1
by: kmacintyre | last post by:
I am trying to us a simple NetworkStream to transfer a file over tcp. This works most of the time, but one specific file never downloads(.mdb file). It seems to close the socket and I get an...
6
by: Ryan | last post by:
Hi, I am confused with how NetworkStream works. My application needs to handle heavy requests sent through TCP socket connection. I use NetworkStream.Read method to get the stream...
4
by: Kai Thorsrud | last post by:
Hi! How do i check: if "NetworkStream.Null = true then" it says .Null does not supports type Boolean Thanks /Kai
1
by: hamid_2020 | last post by:
I wrote a class to connect to a server using tcpclient. I need to connect to the server and the connection must be open.Then i need to send request to the server again and again.But the problem is...
0
by: Al Wilkerson | last post by:
Hey, Has anyone ever got a "Unable to read data from transport connected" message after reading data from a streamreader composed of a networkstream. For example: Server TcpListener...
7
by: littleIO | last post by:
Hi, I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated. I have a server which listens, receives calls, processes them and sends back the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.