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

NetworkStream.DataAvailable

Hi,
When NetworkStream.DataAvailable flag is toogled ?
The explanation of MSDN is so vague and confusing !

Thanks


Nov 15 '05 #1
1 7583
" Hai Ly Hoang - MT00KSTN" <Re**********@Mail.com> wrote in message news:<uV**************@TK2MSFTNGP11.phx.gbl>...
Hi,
When NetworkStream.DataAvailable flag is toogled ?
The explanation of MSDN is so vague and confusing !

The DataAvailable property will be true when data is present on
the socket for reading. The Read() method will block until there is
data that can be read. If you don't want your application to block on
the Read(), you can first check the stream with the DataAvailable
property. If it returns false, you know that the Read() method would
block, and can avoid calling it.

As a side benefit, the DataAvailable property will throw an
Exception if the remote host has closed the stream. By catching that
in a try-catch block you can determine when the remote host has closed
the connection:

try {
if (ns.DataAvailable)
{
int recv = ns.Read(data, 0, data.length)
} else
{
Console.WriteLine("No data available yet");
}
} catch(SocketException)
{
Console.WriteLine("The remote host has disconnected");
ns.Close();
}

Hope this helps clear things up some.

Rich Blum - Author
"C# Network Programming" (Sybex)
http://www.sybex.com/sybexbooks.nsf/Booklist/4176
"Network Performance Open Source Toolkit" (Wiley)
http://www.wiley.com/WileyCDA/WileyT...471433012.html
Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Stelrad Doulton | last post by:
Hi all, I am writting a Jabber-esque client-server application and have run into an issue with the XmlTextReader constructor when passing a NetworkStream - It hangs forever, apparently this is...
0
by: SRLoka | last post by:
I have a TCP server to which a number of mobile devices connect. If a device disconnects(mostly no clean close as they usually lose cell coverage or shutdown), and the server then tries to send...
4
by: 0to60 | last post by:
I have a class that wraps a TcpClient object and manages all the async reading of the socket. It works really nice, and I use it all over the place. But there's this ONE INSTANCE where I create...
2
by: DC | last post by:
Hi, I need to asynchronously read from a network (TCP) stream, and I am having trouble with retrieving whole blocks; I get a break in the data block every 1460 bytes which relates to network...
2
by: Srinivas R. Loka | last post by:
I have a TCP server to which a number of mobile devices connect. If a device disconnects(mostly no clean close as they usually lose cell coverage or shutdown), and the server then tries to send...
4
by: Kai Thorsrud | last post by:
Hi, Thanks a lot for the short path solution to the app i'm working on by including a Perl script ( App i'm converting from perl to .Net) for the part i can't do yet. I'm communicating with a...
3
by: shahla.saeed | last post by:
hi, plzz check my code and let me know where the problem is lying...becuase whenever i try to tansfer the file of 573KB(mp3) it just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time...
1
by: Terry Olsen | last post by:
Need a little help with reading from a network stream. I'm downloading articles from an NNTP server. The end of an article is signified by <CRLF>.<CRLF> For all the talking back & forth, I used...
10
by: ohmmega | last post by:
hello out there, I use a thread data from a linuxserver. i ask for data, i read the data (fix in size) - so far so good. this works great for the first 61 datapackages, then my thread abruptly...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.