Daniel3120
New member
- Joined
- May 23, 2008
- Messages
- 2
- Programming Experience
- 1-3
At the minute when i try to read from the TCPClient NetworkStream, I have no way to set the read buffer to the correct amount of data being received on the stream.
I have tried using TCPClient.Client.ReceiveBufferSize but this is always 8192 even if the data being received is less than that.
It is important because i end up with a load of 0 bytes at the end of the buffer which is causing me a lot of problems.
Does anyone have any ideas on how to get it to set the buffer to the correct size? heres my code so far, its running on a different thread to TCP:
I have tried using TCPClient.Client.ReceiveBufferSize but this is always 8192 even if the data being received is less than that.
It is important because i end up with a load of 0 bytes at the end of the buffer which is causing me a lot of problems.
Does anyone have any ideas on how to get it to set the buffer to the correct size? heres my code so far, its running on a different thread to TCP:
VB.NET:
Private Sub Listen()
Try
Do Until nolisten = True
Do Until ns.DataAvailable
'wait until data available or disconnected
Loop
errtimeout.Stop()
If ns.DataAvailable Then
Dim size As Integer = TCP.Client.ReceiveBufferSize
Dim b(size) As Byte
'ns.Read(b, 0, size)
ns.BeginRead(b, 0, size, New AsyncCallback(AddressOf nsread), b)
End If
Loop
Catch ex As ObjectDisposedException
End Try
End Sub