View Single Post
  #1 (permalink)  
Old 07-09-2009, 4:02 AM
Robert_Zenz's Avatar
Robert_Zenz Robert_Zenz is offline
VB.NET Forum Idol
.NET Framework: .NET 2.0
 
Join Date: Jun 2008
Location: Vienna, Austria
Age: 22
Posts: 503
Reputation: 290
Robert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NETRobert_Zenz master of VB.NET
Default NetworkStream and large amount of data

Hello people.

A while ago I've started to write my own network layer based upon the TCPClient and the NetworkStream.

I'm using a while loop to receive data:
Code:
            Dim buffer(Me.prv_client.ReceiveBufferSize - 1) As Byte
            Dim read As Integer = Int32.MaxValue

            Do
                Try
                    read = Me.prv_strm.Read(buffer, 0, buffer.Length)
                Catch ex As IOException
                    Me.writeError(ex.Message)
                    read = 0
                End Try

                'Do something with it
            Loop While Me.prv_strm.DataAvailable
Unfortunately, this loop is faster then the underlying connection and DataAvalaible is false at some point. This happens especially with a big amount of data (> 500 Kb), 'cause at some point the loop is just faster.
If I know the size of the received data, there's no problem 'cause I read until I have everything. But what I don't have that information?

Of course, using Threading.Thread.Sleep() seems to be a solution, but that one feels just plain wrong.

Anyone some ideas on that?
Bobby
__________________
Don't give TypeCasting Errors a chance, turn ON Option Strict!
Greatest Obfuscator ever: EazFuscator (Freeware)
Greatest Reflection Tool ever: .NET Reflector (Freeware) with Add-Ins
Greatest Introspection Tool ever: Gendarme (GPL)
Greatest MySQL FrontEnd ever: MySQL-Front (Shareware), HeidiSQL (GPL)
Reply With Quote