Solved

http listener

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

Suggested Solutions

Title # Comments Views Activity
Generate Numbers in JQuery file 11 66
Where is this file? 3 26
C#.net split string and then check appropriate checkboxlist 4 27
MYSQL responding very slow 3 26
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

820 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