networkstream problem

Hi,

I am grabbing a page off a web server using networkstream, but I am finding that I am getting data corruption.  The corruption occurs at the end of each data packet recieved, almost as though networkstream is reporting the length of the data read wrong (bRead) resulting in junk data at the end of the buffer, it does appear to be the case  that I am getting ALL of the expected data as well.  A snippet of the code I am using is this:

        Dim bdata = New [Byte](client.ReceiveBufferSize - 1) {}
        If netStream.CanRead Then
            Dim bRead As Int32
            Do
                bRead = netStream.Read(bData, 0, bData.Length)
                Debug.Print("Bytes Read: " & bRead)
                If bRead > 0 Then
                    responseData = responseData & Encoding.ASCII.GetString(bData, 0, bRead)
                End If
            Loop While bRead > 0
        Else
            client.Close()
            netStream.Close()
        End If

The web server is running on port 80, if I point a browser at the page the source looks fine so its not corruption at the server end.  I was checking for the end of the data stream using DataAvailable but found that I was losing the last chunk of data (a documented issue).

Am I missing something obvious here or is there a bug in the networkstream object

Cheers

Si

 

 

 



Answer this question

networkstream problem

  • Cornelius Mostert

     

    OK, I have given up on the networkstream class, tried everything even the microsoft examples but none of them seem to work properly.  Although one thing I have noticed is that every single networkstream code example out there only ever attempts to get a single data packet......  Hmmm....

    Anyway I have switched to using the sockets class, seems to work fine - need to run a few more test tho to make sure it is stable.   (my experiences with VB .NET 2005 over the past couple of weeks are leading me to believe its more beta quality than release...)

    Cheers
    Si

     

     


  • networkstream problem