0

When i read this: How to properly and completely close/reset a TcpClient connection?

I got knowledge that GetStream and the Client are pretty much 2 different objects. Which would mean that i would have to dispose of them.

What i don´t however get is if it really is like this.

Cause Visual Studio Analyze always tells when a Disposable Item isn´t disposed (even if it is later, but it really want you to use Using). And it has never said anything about GetStream().

However, if it is correct anyway, does that mean i would have to use something like this:

            using (tt1 = tcplisten.AcceptTcpClient())
            using(var tcpstream = tt1.GetStream())

It just seems, weird, but i don´t want disposable resources laying about, so better get to the bottom of it.

Community
  • 1
  • 1
Zerowalker
  • 761
  • 2
  • 8
  • 27

1 Answers1

1

Closing the client will not close the stream associated with it. Therefore you will need to call

tt1.GetStream().Close();
tt1.Close();

If you just close the client then the stream will remain active and can still occupy resources.

Paddy
  • 938
  • 1
  • 6
  • 15