Larry Brister
asked on
http listener
In my attached code...it starts and I get to the "Console.WriteLine section
How can I do this in a WinForm so that I can watch anything the listener pick up?
How can I do this in a WinForm so that I can watch anything the listener pick up?
Public Shared Sub SimpleListenerExample(inboundprefixes As String)
If Not HttpListener.IsSupported Then
MsgBox("Listener Not Supported", vbOKOnly, "Action")
Return
End If
' URI prefixes are required,
' for example "http://someurl.com:8080/index/".
If inboundprefixes Is Nothing OrElse inboundprefixes.Length = 0 Then
Throw New ArgumentException("prefixes")
End If
' Create a listener.
Dim listener As New HttpListener()
' Add the prefixes.
' For Each s As String In prefixes
listener.Prefixes.Add(inboundprefixes)
'Next
listener.Start()
Console.WriteLine("Listening...")
' Note: The GetContext method blocks while waiting for a request.
Dim context As HttpListenerContext = listener.GetContext()
Dim request As HttpListenerRequest = context.Request
' Obtain a response object.
Dim response As HttpListenerResponse = context.Response
' Construct a response.
Dim responseString As String = "<HTML><BODY> Hello world!</BODY></HTML>"
Dim buffer As Byte() = System.Text.Encoding.UTF8.GetBytes(responseString)
' Get a response stream and write the response to it.
response.ContentLength64 = buffer.Length
Dim output As System.IO.Stream = response.OutputStream
output.Write(buffer, 0, buffer.Length)
' You must close the output stream.
output.Close()
listener.[Stop]()
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER