Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

http listener

Posted on 2013-05-20
2
Medium Priority
?
391 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

604 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