I've made a post last Friday in regards to this subject, but I'm still a
little lost.
I've a problem regarding reading a stream. I am connected to a port that
sends information using a stream. I can read the information from the stream
with no problem. However, the problem comes when there is nothing to read in
the stream. The stream is still open, so it just hangs on my Read().
EXA:
byte[] buffer = new buffer[2048];
int nBytes
while ((nBytes = this.m_stream.R ead(buffer, 0, buffer.Length)) 0)
{
// Process bytes
}
Well, my problem -- as mentioned -- is here. For example, if the stream
only sends 64 bytes. I will read once, I will process once, and then I will
jump to back to the top of the while-statement where it will Read() again,
but it will just hang here. Should I be doing active monitoring on the
buffer to determine if the EOF string has been received? In my case, the EOT
is three hashmarks: ###. Should I be watching for the three hashmarks and
break out of the loop to prevent hanging?
If I should be watching for the EOT, or ###, should I also watch for the EOT
on a boundary? For example, in one packet it may send ## and the next packet
may contain a solitary #. Or, another example, if I read 2048 of bytes, that
will fill up my entire buffer. The last byte in the buffer may be a #. Then
I read again on the stream and the next two -- and only bytes -- are ##.
Well, this would mean I am at the end. Thank you.
Trecius 2 1954
Hello Trecius,
you can use a non blocking read by using BeginRead instead of Read, you will
probably find a example for this on google.
Regards
Winfried Wille
On Mon, 20 Oct 2008 11:19:01 -0700, Trecius
<Tr*****@discus sions.microsoft .comwrote:
[...]
Well, my problem -- as mentioned -- is here. For example, if the stream
only sends 64 bytes. I will read once, I will process once, and then I
will
jump to back to the top of the while-statement where it will Read()
again,
but it will just hang here. Should I be doing active monitoring on the
buffer to determine if the EOF string has been received? In my case,
the EOT
is three hashmarks: ###. Should I be watching for the three hashmarks
and
break out of the loop to prevent hanging?
You haven't explained exactly what kind of stream this is. But yes, if
the stream itself doesn't have a natural "end" (e.g. a FileStream would
reach the actual end of the file, a NetworkStream would be closed, etc.),
then you'll have to watch the data yourself.
And yes, since the three-byte terminator for the stream may be read in
separate parts in separate calls to Read(), you need to correctly deal
with that.
Pete This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Hendrik Schober |
last post by:
Hi,
I have a 'std::istream' and need to read
its whole contents into a string. How can
I do this?
TIA;
Schobi
|
by: Ali |
last post by:
Hi
I want to write (or read) to a stream, but the data is not byte array
I converted the data to byte array manually, but it is very slow, (becuse the data is very large)
Is another way for this kind of writing and reading
best regard
Ali.
|
by: frustrated |
last post by:
I am trying to share a file stream between two threads,
but havent got a clue as to how to do it.
The first thread will be reading the file, and the second
thread will(/might) be writing to the same file stream. I
was going to pass a ref to the file stream to the second
thread, but the problem comes when I am trying to read
from one section of the stream and write to another. I
dont want one thread changing the position of the stream...
|
by: Marc Thompson |
last post by:
Hi there,
I have the following:
Dim objResponse As WebResponse = objReq.GetResponse
Dim objStream As IO.Stream
objStream = objResponse.GetResponseStream
Then, I read some Bytes from this stream and it works. I then go do some
|
by: Divick |
last post by:
Is there a way in C++ to have a file stream which is directly mapped to
memory(virtual memory) without actually having to create a file and
then memory mapping that file using system dependent calls?
I need this because I don't want to create a regular file on disk
(reasons for which are many , say directory permissions ), but being a
file pointer, someone can use that pointer as a regular file descriptor
for reading and writing.
...
| |
by: T Driver |
last post by:
Anyone have any idea how I can do the following?
I have a connection to an XML file on a site I do not control, getting
a string representation of the xml data that I can then feed to my
XmlDataSource object (CurrentXMLData):
Stream newStream =
myWebClient.OpenRead(myStringWebResource);
TextReader newReader = new StreamReader(newStream);
string newData = newReader.ReadToEnd();
CurrentXMLData.Data = newData;
|
by: Morgan Cheng |
last post by:
I am using C# to write a crawler-like program. The program reads
several URI pages sequentially and store HTTP response into a single
byte array. The job should be done in specific time. So, I have both
size limit and time limit.
My current solution is like this. use
HttpWebResponse.GetResponseStream to get the I/O stream. Read from it
with asynchronous BeginRead. In the callback, check whether time and
space is up. If yes, then stop;...
|
by: =?Utf-8?B?VHJlY2l1cw==?= |
last post by:
Hello, Newsgroupians:
In regards to reading a stream, I know we use the Read() method. One could
implement reading a stream using a while-loop.
while (stream.Read(buffer, 0, buffer.Length) != 0)
{
// Process the buffer
}
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
I have a fully-portable C program (or at least I think I do). It works
fine on Windows, but malfunctions on Linux. I suspect that there's
something I don't know about the standard input stream that's causing
the problem.
Here's how I wrote the program originally:
#include <stdio.h>
#include <string.h>
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |