Solved

http listener

Posted on 2013-05-20
2
383 Views
Last Modified: 2013-05-20
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?

    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

Open in new window

0
Comment
Question by:lrbrister
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 500 total points
ID: 39181284
Mmmmm... place a TextBox with MultiLine property = true
Instead of Console.WriteLine(text) do TextBox1.Text += text + vbCrLf

Hope that helps.
0
 

Author Closing Comment

by:lrbrister
ID: 39181451
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question