Stream Length

J

Joseph Byrns

I am using streams and the OpenNetCF Bluetooth stuff to access a BT serial
adapter, which usually works fine. However when there is no data in the
stream to be collected the stream.Read(buffer,0,length) just freezes. If I
try to identify if data exists first using stream.length, I get the
following error: "This stream does not support seek operations"

The following is the code I am using:
Dim strm As Stream = ConnectedBTClient.GetStream
strm.Flush()
strm.Write(System.Text.Encoding.ASCII.GetBytes(vbCr & "M"), 0, 2)

Dim tmpStr As String
Dim bytesRead As Integer
Dim buffer(128) As Byte
For i = 1 To 10
If Not strm.Length>0 Then ''get above error here if use this in code
bytesRead = strm.Read(buffer, 0, 128) ''freezes here if nothing to
read
If bytesRead > 0 Then
tmpStr += System.Text.Encoding.ASCII.GetString(buffer, 0,
bytesRead)
End If
Endif
Next i

any ideas appreciated.
 
J

Joseph Byrns

Problem solved, if I use a NetworkStream instead of a Stream then I can use
NetworkStream.DataAvailable to make sure the data is there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top