473,395 Members | 1,442 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,395 software developers and data experts.

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 5244
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 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: 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...
2
by: Nuno Magalhaes | last post by:
In a simple code I do something like this in a synchronous connection: -*server*----------------------------- ClientTcp=ListenerTcp.AcceptTcpClient(); NetworkStream nstream=ClientTcp.GetStream();...
2
by: JeremyH | last post by:
I'm trying to create a simple, synchronous TCP client program to receive requests and return data. My code very closely resembles the example code provided in the Help files, but I find that the...
7
by: david.topham | last post by:
Hi The code below demostrates an issue I'm having with with NetworkStream: using System; using System.Net.Sockets; namespace TCPCTest { class Class1
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...
2
by: PiotrKolodziej | last post by:
Hi I have a simple question. Here is the code related to my question: while (true) { if (tcpListenerServer.Pending() && !this.Disposing) { TcpClient tcpClient =...
5
by: | last post by:
I've got a basic "chat" infrastructure that can send objects across the wire, but I'm running into a few issues with trying to send multiple messages and things behaving differently in debug and...
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...
3
by: A. W. Dunstan | last post by:
I have an application that wants to open a Socket, write data and close the socket. A persistent connection would be nice, but it's intended to operate in an environment where the network...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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:
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.