Solved

http listener

Posted on 2013-05-20
2
379 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
Comment Utility
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
Comment Utility
Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now