请Socket高手进来指导!谢谢
Dim Port As String = "80"
Dim ip() As System.Net.IPAddress = System.Net.Dns.GetHostAddresses("www.google.com")
hostip = ip(0).ToString
Dim ipp As IPAddress
ipp = IPAddress.Parse(hostp)
Dim serverhost As New IPEndPoint(ipp, Int32.Parse(Port))
Dim clientSocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
clientSocket.Connect(serverhost) '连接服务器
get = "GET /" & " HTTP/1.1" + vbCrLf
Dim asci1 As Encoding = Encoding.ASCII
clientSocket.Send(asci1.GetBytes(get))
Dim buffer1(1024) As Byte
Dim byteCount1 As Int16 = clientSocket.Receive(buffer1, buffer1.Length, 0)
shuju = asci1.GetString(buffer1, 0, byteCount1)
Do While byteCount1 > 0
byteCount1 = clientSocket.Receive(buffer1, buffer1.Length, 0)
shuju = shuju & asci1.GetString(buffer1, 0, byteCount1)
Loop
//问题在这里,需要循环很长时间才能接受完数据,请问是不是我那里没有写对呢?
'MsgBox("GET 5")
clientSocket.Close()
clientSocket = Nothing
clientSocket.Receive 接受数据非常慢,同样的网站,用浏览器访问很快的。
请问如何设置一个超时,或者如何加快速度。 总感觉代码有问题。
但代码是在网上找的,资料也很少。
[解决办法]
别的网站也很慢吗?
[解决办法]
你用异步的就好了。同步的可能会卡。