Re: Read from TCP Stream greater then buffer size
From: Rob (Rob_at_discussions.microsoft.com)
Date: 11/28/04
- Next message: Alex Levi: "RE: How to save data withought database ?"
- Previous message: Nak: "OT: Post development issues"
- In reply to: Ken Tucker [MVP]: "Re: Read from TCP Stream greater then buffer size"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 28 Nov 2004 06:35:01 -0800
Thanks Ken, I had been basing my code on this article.
I've ended up with a simple loop
Dim sb As New StringBuilder
While NStream.DataAvailable
Try
numberOfBytesRead = NStream.Read(bytes, 0,
CInt(Connection.ReceiveBufferSize))
sb.Append(Encoding.ASCII.GetString(bytes, 0,
numberOfBytesRead))
Catch ex As Exception
Exit While
End Try
End While
If I run it with breakspoint in debug and step thru the loop iterations I
get a full set of groups returned - I keep a byte count which comes back with
over 100k data returned. If I run it without breakpoints I get a partial list
back with a total byte count of 5040. I've varied by buffersize but this
appears to have no impact.
The fact it works under debug probably means the code is correct but it
appears to be a timing/syncing thing.
I've built the example from the URL above (and from another) and they work -
but they are in c# - is it a VB thing?
"Ken Tucker [MVP]" wrote:
> Hi,
>
> Maybe this will help.
> http://www.programmersheaven.com/2/Art_CSharp_4
>
> Ken
> -------------------
> "Rob" <Rob@discussions.microsoft.com> wrote in message
> news:85A61B6D-A8F6-48E7-B012-B9B68F0B90E8@microsoft.com...
> I'm pretty new to VB .net and Network coding, what I'm trying to do is
> interact with a NNTP server to retrieve a list of news groups.
>
> When I run thru' debug I basically get what I'm after, when I run without
> debug the results vary - which to me suggests it's some form of sync problem
> with my 'writes and reads'.
>
> I've set up a connection to a server and have sent a 'List' command to get a
> 'group list', I've set up my connection buffer at 32k, I'm assuming I'm
> blocking on the stream read, the question is how to I control receiving a
> complete returned message - which could be 500k. I've tried various do-loop
> controls, some based on MSDN examples such as 'Loop While
> NStream.DataAvailable' and the attached which I'd hoped would loop until a
> message which was less then the complete buffer was returned - but it all
> seems hit and miss.
>
> thanks
>
> Dim numberOfBytesRead As Integer = 0
> Dim sb As New StringBuilder
>
> Do
> numberOfBytesRead = NStream.Read(bytes, 0, CInt
> Connection.ReceiveBufferSize))
> If numberOfBytesRead = 0 Then
> Exit Do
> End If
> sb.Append(Encoding.ASCII.GetString(bytes, 0, numberOfBytesRead))
> totallength = sb.Length
> Loop Until numberOfBytesRead < Connection.ReceiveBufferSize
>
>
>
>
>
- Next message: Alex Levi: "RE: How to save data withought database ?"
- Previous message: Nak: "OT: Post development issues"
- In reply to: Ken Tucker [MVP]: "Re: Read from TCP Stream greater then buffer size"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|