469,631 Members | 1,253 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

networkStream.Write waits until networkstream.close

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.

I am sending a small amound of data and read where data wasn't sent
until the buffer reached a larger size. However, there is a
TcpClient property call NoDelay that is suppose to eliminate this
delay. Here is a snippet of my code below. Can anyone think of a
reason why the networkStream.Write isn't performed until the
networkstream is closed?

Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("i set ip here", "and port here")
//connection occurs as expected
tcpClient.NoDelay() = True

Dim networkStream As NetworkStream = tcpClient.GetStream()

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("test")
If NetworkStream.CanWrite And NetworkStream.CanRead Then
' Do a simple write.
networkStream.Write(sendBytes, 0, sendBytes.Length)
//this .write is returned but the data is not sent until a
networkstream.close is performed

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 22 '05 #1
1 4329
cmjman wrote:
I have an issue where networkStream.Write doesn't perform its write
downstream from my client program until the network stream is closed.
That's because streams are buffered, and need to be Flush()'ed to force
sending data.

Buffering allows the runtime/OS to do much more efficient transmits.
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("i set ip here", "and port here")
//connection occurs as expected
tcpClient.NoDelay() = True
Assigning to the output of functions rarely work, since the functions
usually doesn't return references. I don't know the specifics of the
NoDelay function, but I would be very suprised if the above line
actually changed the NoDelay for tcpClient.
Dim networkStream As NetworkStream = tcpClient.GetStream()

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("test")
If NetworkStream.CanWrite And NetworkStream.CanRead Then
Why do you even check this? wouldn't you rather have an error if you
couldn't send?
' Do a simple write.
networkStream.Write(sendBytes, 0, sendBytes.Length)


networkstream.Flush()

--
Helge
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by kmacintyre | last post: by
2 posts views Thread by Nuno Magalhaes | last post: by
7 posts views Thread by david.topham | last post: by
2 posts views Thread by PiotrKolodziej | last post: by
3 posts views Thread by A. W. Dunstan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.