Solved

http listener

Posted on 2013-05-20
2
382 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

15 Experts available now in Live!

Get 1:1 Help Now