将收到的数据写回浏览器时,为什么我的NetworkStream.Write()会变慢?

时间:2012-04-13 05:49:15

标签: vb.net

我正在服务器vb.NET中构建一个简单的代理,到目前为止它已经成功,但是每当我从互联网接收数据并使用NetworkStream.Write将其写回我的浏览器的网络流时,收到的数据趋于由于我不知道的原因,慢慢来到我的浏览器。但是,当我将我的应用程序链接到本地​​计算机上的另一个代理/侦听器(例如Privoxy)时,数据似乎很快就出现在我的浏览器中。如果有人对此有答案,我真的很想知道。感谢

btw这是我的代码{subroutine}的一部分,它接收数据并转发到我的浏览器。

 Public Sub ForwardRequest(ByVal Client As TcpClient, ByVal ClientMessage As String)

        Dim Browser As TcpClient = Client
        Dim BrowserStream As NetworkStream = Browser.GetStream
        Dim Server As TcpClient = New TcpClient(IPAddress.Parse("testwebsite.com").ToString, 80)
        Dim ServerStream As NetworkStream = Server.GetStream

        ServerStream.Write(Encoding.ASCII.GetBytes(ClientMessage), 0, Encoding.ASCII.GetBytes(ClientMessage).Length)

        Dim Buffer(1024) As Byte
        Dim ReceivedInt As Integer

        Do
            ReceivedInt = ServerStream.Read(Buffer, 0, Buffer.Length)
            BrowserStream.Write(Buffer, 0, ReceivedInt)
        Loop While (ReceivedInt > 0)

        BrowserStream.Flush() 'I read somewhere that this does nothing though
        BrowserStream.Close()
        Browser.Close()
        ServerStream.Close()
        Server.Close()

    End Sub

1 个答案:

答案 0 :(得分:0)

好的,我设法解决了这个谜团"我自己,我继续使用Asynchronous Sockets套接字,一切都开始运作良好。 感谢。