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