Public myip2 As IPAddress = IPAddress.Parse("127.0.0.1")
Const portNumber As Integer = 8889
Public MyHost As String = System.Net.Dns.GetHostName()
Public MyIp As IPAddress = System.Net.Dns.GetHostByName(MyHost).AddressList(0)
Public mytcplistener As New TcpListener(myip2, portNumber)
Public listeningthread As Thread
Public Sub startserver()
listeningthread = New Thread(AddressOf listening)
listeningthread.Start()
End Sub
Public Sub listening()
mytcplistener.Start()
Dim mytcpclient As TcpClient = mytcplistener.AcceptTcpClient
Dim bytes(mytcpclient.ReceiveBufferSize) As [Byte]
Dim msg As [String]
Dim readstream As NetworkStream = mytcpclient.GetStream
readstream.Read(bytes, 1024, CInt(mytcpclient.ReceiveBufferSize))
msg = Encoding.ASCII.GetString(bytes)
Dim sURL As String = " "
Dim index1 As Integer = msg.IndexOf(" "c)
Dim index2 As Integer = msg.IndexOf(" "c, index1 + 1)
Dim part1 As String = msg.Substring(index1 + 1, index2 - index1)
Dim index3 As Integer = part1.IndexOf("/"c, index1 + 8)
Dim index4 As Integer = part1.IndexOf(" "c, index1 + 8)
Dim index5 As Integer = index4 - index3
sURL = part1.Substring(index1 + 4, part1.Length - index5 - 8)
Dim sTMP As String
sTMP = sTMP & "<HTML><HEAD><TITLE>sss</TITLE></HEAD><br>" & vbCrLf
sTMP = sTMP & "<BODY BGCOLOR=" & Chr(34) & "#FFFFFF" & Chr(34) & " Text=" & Chr(34) _
& "#000000" & Chr(34) & " LINK=" & Chr(34) & "#0000FF" & Chr(34) & " VLINK=" & Chr(34) _
& "#000080" & Chr(34) & " ALINK=" & Chr(34) & "#008000" & Chr(34) & "><br>" & vbCrLf
sTMP = sTMP & "<b>500</b> ssss<br>" & vbCrLf
sTMP = sTMP & "</BODY><br>" & vbCrLf
sTMP = sTMP & "</HTML><br>" & vbCrLf
bytes = Encoding.Unicode.GetBytes(sTMP)
readstream.Write(bytes, 1, bytes.Length)
End Sub
Public Sub stopserver()
mytcplistener.Stop()
End Sub