Private Sub btnHTML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnHTML.Click Dim serverIP As IPAddress =
Dns.Resolve("http://www.Tuenhai.com").AddressList(0) '
Default Web Server Port = 80 Dim Port As String = "80" Dim serverhost
As New IPEndPoint(serverIP, Int32.Parse(Port))
Dim clientSocket As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
Try clientSocket.Connect(serverhost)
If clientSocket.Connected = False Then MsgBox("Connect Error.",
MsgBoxStyle.Critical, "HTTP") Exit Sub End If
Dim httpReq As String = "GET / HTTP/1.0" & ControlChars.CrLf &
ControlChars.CrLf
clientSocket.Send(ASCII.GetBytes(httpReq))
Dim buffer(1024) As Byte Dim byteCount As Int16 =
clientSocket.Receive(buffer, buffer.Length, 0)
txtHTML.Text = ASCII.GetString(buffer, 0, byteCount)
Do While byteCount > 0 byteCount =
clientSocket.Receive(buffer, buffer.Length, 0) txtHTML.Text =
txtHTML.Text & ASCII.GetString(buffer, 0, byteCount) Loop Catch
ex As Exception MsgBox(ex.StackTrace.ToString(), MsgBoxStyle.Critical,
"Exception") End Try End Sub |