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
|