NetworkStream

  • Thread starter Thread starter Kai Thorsrud
  • Start date Start date
K

Kai Thorsrud

Hi!

How do i check: if "NetworkStream.Null = true then" it says .Null does not
supports type Boolean

Thanks
/Kai
 
Kai,
Can you provide significantly more information as to what the problem is. As
what you have doesn't have ANY context with it, so we don't really know what
you are talking about or referring to.

Providing about 5 to 10 lines of code on what you are doing would be
helpful, especially if those 5 to 10 lines compile (by themselves) with the
error you are seeing! Then we at least have a context on what is going
wrong.

BTW: NetworkStream is a class in the System.Net.Sockets namespace, however
it does not have a Null property, so obviously you cannot check to see if
"null" is true or not?

Hope this helps
Jay
 
Kai Thorsrud said:
i'm passing Network streams between classes and i want to check if
the stream still is open. According to my MSDN help you are correct
that there are no Null property but according to .Net it seems so and
it seems to fulfill what i want to check. it must be something wrong
with my .Net install then or is it some class inherentace from
objects in general ?

However canread fails if the stream is not open so where do i put my
check ?

Does the DataAvailable property help?
look at attached picture

Null is a shared member. It is actually System.IO.Stream.Null and points to
a "Null"-Stream. See docs on Null member.
 
Kai,
but according to .Net it seems so and it seems to
fulfill what i want to check.
O.K. I see what you are seeing. You are seeing Stream.Null which is a "Null
Object". "Null Object" is a specific application of the Special Case
Pattern. http://www.martinfowler.com/eaaCatalog/specialCase.html

Null objects are useful in routines where you do not want to be constantly
checking to see if an object reference is Nothing (Null) or not. They are
not used to see if a Stream is open or not per se.

To check to see if you were passed Stream.Null or not you would use the Is
operator. However generally you should be writing your routines in such a
manner that it doesn't matter if you were passed a real Stream or
NetworkStream object, or the Stream.Null object.

Dim myStream As NetworkStream

If myStream Is Stream.Null Then

End If

Because NetworkStream inherits from Steam, you can use NetworkStream.Null
instead.
i'm passing Network streams between classes and i want to check if the
stream still is open.
I do not know how to verify if the stream itself is open or not. Its not
Stream.Null as Stream.Null is a shared field (not an instance property).

Hope this helps
Jay
 
Back
Top