WebClient.DownloadString比TcpClient快12倍?

时间:2014-06-21 05:59:50

标签: c# vb.net sockets webclient networkstream

现在是8个小时,我还在努力弄明白。代码示例将在VB.NET中,但我认为它们对C#用户也是可读的。哦,我也接受C#解决方案。

这最多需要50毫秒:

Dim Data as String = wc.DownloadString("x.com")

虽然平均需要600毫秒:

Dim client As New Net.Sockets.TcpClient
client.NoDelay = True
client.Client.NoDelay = True
client.Connect(IP, 80)
Dim ns As Net.Sockets.NetworkStream = client.GetStream
Dim gbytes(70000) As Byte
ns.Write(rbytes, 0, rbytes.Length)
ns.Flush()
ns.Read(gbytes, 0, gbytes.Length)
Dim Data as String = System.Text.Encoding.ASCII.GetString(gbytes)

是的,我尝试过流阅读器,不同的缓冲区大小包括少于和多于响应的长度(大约100,000字节)。我正在使用WebClient使用的完全相同的标题,并尝试了不同的标题。我也尝试过NoDelay的每一个组合。

问题是,我不想使用WebClientNetworkStream.Flush被评论为在.NET中无用,那么还有出路吗?

0 个答案:

没有答案