tags:

views:

38

answers:

1

My app currently sends GET httpwberequests and parses the content after reading the response stream for each request and the repeats this process over and over. I need to implement a continuous http stream which uses the same GET request but the connection stays open, from what I understand. how would I change my existing code to do this?

       Dim responseReader As StreamReader = Nothing   
        Dim Reader As StreamReader = Nothing
        Dim responseData As String = ""
        Dim webresponse As HttpWebResponse = Nothing
        Dim responseStream As Stream = Nothing
        Dim returnContent As String = Nothing
        Dim cdata As Integer = 0

         webRequest = TryCast(System.Net.WebRequest.Create(url), HttpWebRequest)

        Try

            webresponse = DirectCast(webRequest.GetResponse(), HttpWebResponse)
            responseStream = webresponse.GetResponseStream
            If webresponse.ContentEncoding.ToLower().Contains("gzip") Then
              responseStream = New GZipStream(responseStream,  CompressionMode.Decompress)
            ElseIf webresponse.ContentEncoding.ToLower().Contains("deflate") Then
                responseStream = New DeflateStream(responseStream, CompressionMode.Decompress)
            End If

            Reader = New StreamReader(responseStream, Encoding.Default)
            responseData = Reader.ReadToEnd()

        Catch
            Throw
        Finally
            webRequest.GetResponse().GetResponseStream().Close()
            Reader.close()

        End Try

        Return responseData

The streaming HTTP implementation allows one to cosume data in real time over a single persistent HTTp request. It access a data feed that continues to send activities on that response. I need to read data from the response, process it and then continue reading from the response and continue this process until the connection is closed. Would this be like a asynchronous request instead?

A: 

This is actually one of the goals of HTML5. You can take a look at http://socket.io/ to see implementations that work for HTML4 browsers

Anthony Greco