Robert_Zenz
Well-known member
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:
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
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:
VB.NET:
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
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