473,320 Members | 2,147 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,320 software developers and data experts.

Stream Reader blues.



Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:

A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if
it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?

Thanks for all the help you ppls can give me. Unfortunatly
the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)
Nov 20 '05 #1
5 950
Unless their is something I am missing you can check to see if the byte
array that was returned is less than the requested length.

Public Overridable Function ReadBytes( ByVal count As Integer) As Byte()

"jamie" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...


Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:

A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if
it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?

Thanks for all the help you ppls can give me. Unfortunatly
the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)

Nov 20 '05 #2
* "jamie" <an*******@discussions.microsoft.com> scripsit:
Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"


<URL:http://www.yoda.arachsys.com/csharp/readbinary.html>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #3
Jamie,
As spamtrap suggested, you can check the size of the array returned.

If any method of BinaryReader threw an exception while I was using it, I
would not care if the position was advanced or not, as I would consider the
entire BinaryReader to be invalid and get ride of it!

Hope this helps
Jay

"jamie" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...


Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:

A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if
it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?

Thanks for all the help you ppls can give me. Unfortunatly
the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)

Nov 20 '05 #4
oh yea, the array is dimensioned in the method, so I could
use array.length . I could work with that.

thanks

-----Original Message-----
Unless their is something I am missing you can check to see if the bytearray that was returned is less than the requested length.

Public Overridable Function ReadBytes( ByVal count As Integer) As Byte()
"jamie" <an*******@discussions.microsoft.com> wrote in messagenews:0b****************************@phx.gbl...


Im trying to use a binaryreader to read in afew variables from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:
A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?
Thanks for all the help you ppls can give me. Unfortunatly the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)

.

Nov 20 '05 #5
PERFECT!!!! thats what I needed!!!
-----Original Message-----
* "jamie" <an*******@discussions.microsoft.com> scripsit:
Im trying to use a binaryreader to read in afew variables from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"


<URL:http://www.yoda.arachsys.com/csharp/readbinary.html>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
.

Nov 20 '05 #6

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

Similar topics

4
by: Leon Jollans | last post by:
Hi. I'm reading a 5 meg (or so) file from the response stream of a WebRequest, and it's pitifully slow. I mean *really* slow, in the order of 15 minutes to download. Now obviously I'm caching this...
6
by: Yechezkal Gutfreund | last post by:
I have been using the following code (successfully) to read Xml formated text packets from a TCP stream. The output from the server stream consists of a sequence of well formed Xml documents...
5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
8
by: Scott | last post by:
Hi guys, If I try to call read(), readline(), readtoend() and there is nothing to read (from a never ending loop for example) the program seems to continue but it exits the loop for no apparent...
6
by: Rob Meade | last post by:
Hi all, I'm having a few difficulties with the above, ie I cant find any good examples anywhere of how to do what I want to do! I have an xml file on my desktop which I want to read in. ...
7
by: .... | last post by:
Hi I have an existing function which has a stream object (inmsg.BodyPart.Data). I'm trying to search and replace the stream object in the most efficient way possible This is my attempt below,...
10
by: John Kraft | last post by:
Hello all, I'm experiencing some, imo, strange behavior with the StreamReader object I am using in the code below. Summary is that I am downloading a file from a website and saving it to disk...
3
by: Martin Z | last post by:
Hi, I have an application that involves sending a lot of XML data to various places. The problem is that once in a while, I just want the XML document as a string (for example, sending to a...
2
by: Jack | last post by:
Hi, I want to read a string a chars from a stream, and put it into a string. At the moment, I'm creating a buffer of a fixed size, and reading the stream of text into it. It works, but I have...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.