I wrote a little web server though it is not working it pops up the following exception: Imports
System.Net.HttpListenerException: Failed to listen on prefix 'http://*:80/myserver/' - the call to httpapi.dll!HttpAddUrl failed.
at System.Net.HttpListener.AddAll()
at System.Net.HttpListener.Start()
at ConsoleApplication1.Module1.Main() in C:\Documents and Settings\Shmuel\My Documents\Visual Studio\Projects\Webserver\Webserver\Module1.vb:line 16
This is my code:
Imports
System.TextImports
System.IOImports
System.Threading
Module
Module1 Sub Main() Try Dim rMessage As Byte() = Encoding.ASCII.GetBytes("trying to send me") Dim listener As New HttpListenerlistener.Prefixes.Add("http://*/myserver/")
listener.Start()
While (True) Dim context As HttpListenerContext = listener.GetContext() Dim request As HttpListenerRequest = context.Request()Console.WriteLine("Recived Request from" + request.Url.ToString())
Dim response As HttpListenerResponse = context.Response()response.ContentLengthLong = rMessage.Length * 10
response.StatusCode = 200
response.ContentType = "html/text"
Dim s As Stream = response.OutputStream Dim i As Integer For i = 0 To i < 10Console.WriteLine("sending row #.", i)
s.Write(rMessage, 0, rMessage.Length)
Thread.Sleep(500)
Next
s.Close()
response.Close()
End While Catch ex As Exception Try My.Computer.FileSystem.WriteAllText("ErrorLog.txt", ex.ToString, True) Catch fileException As Exception Throw fileException End TryConsole.WriteLine(ex)
End TryEnd Sub
End
Module
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.