0

my current code has a TCPclient connection set up, i want to write some data (a string: UserName) to it.

using outStream as new streamwriter(client.getstream)
  outStream.write(UserName)
end using

my problem with this code is that it disposes of the client when it is finished and I need to keep the client open. if I change the using to a dim and do not dispose of the streamwriter, the data does not actually get written and so i want to know whether how i can send the data and keep the client open.

maxG795
  • 61
  • 7

1 Answers1

0

Closing a StreamWriter will close the connection stream. .NET 4.5 added an overload to the StreamWrite that gives the ability to keep the stream opened.

Is there any way to close a StreamWriter without closing its BaseStream?

An other option is to not use Using and sticking with a Dim and closing the stream only at the end. If you want to force the data to be sent, you'll have to call flush.

http://msdn.microsoft.com/en-us/library/vstudio/system.io.streamwriter.flush

Community
  • 1
  • 1
the_lotus
  • 12,668
  • 3
  • 36
  • 53