Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:21:42+00:00 2026-06-05T06:21:42+00:00

I’ve created a Http Server in VB.net. I’ve used the same template, I guess

  • 0

I’ve created a Http Server in VB.net. I’ve used the same “template”, I guess you could say, for every project requiring an Http Server (quite a few recently). The problem is, this one I’m working with now requires that the computers on the LAN be able to connect to it. I can access the server directly from my computer though using: http://127.0.0.1:8002/. Here is my source code (skimmed down of course):

Imports System.Net
Imports System.IO
Imports System.Web
Imports System.Text
Imports System.Text.RegularExpressions
Imports Microsoft.Win32

Public Class MainWindow

    Private Enum ApplicationSituation
        Idle
        Login
        TrackPage
    End Enum

    Private CurrentApplicationSituation As ApplicationSituation = ApplicationSituation.Idle

    Private listener As New HttpListener
    Private theService As String

    Private Const PORT As Integer = 8002
    Private Const SERVERNAME As String = "Poptimas"

    Private ContentTypes As New Dictionary(Of String, String)

    Private ServerThread As Threading.Thread

    Private Sub WriteContentTypes()
        '(TEXT) Human-readable text and source code
        ContentTypes.Add(".txt", "text/plain")
        ContentTypes.Add(".htm", "text/html")
        ContentTypes.Add(".html", "text/html")
        ContentTypes.Add(".xml", "text/xml")
        ContentTypes.Add(".css", "text/css")
        ContentTypes.Add(".csv", "text/scv")
        ContentTypes.Add(".htc", "text/x-component")
        ContentTypes.Add(".js", "application/javascript")
        '(IMAGE)
        ContentTypes.Add(".png", "image/png")
        ContentTypes.Add(".jpg", "image/jpg")
        ContentTypes.Add(".bmp", "image/bmp")
        ContentTypes.Add(".gif", "image/gif")
        ContentTypes.Add(".tiff", "image/tiff")
        ContentTypes.Add(".ico", "image/vnd.microsoft.icon")
        '(AUDIO)
        ContentTypes.Add(".mp3", "audio/mp3")
        ContentTypes.Add(".wav", "audio/vnd.wav")
        ContentTypes.Add(".ogg", "audio/ogg")
        ContentTypes.Add(".mwa", "audio/x-ms-wma")
        '(VIDEO)
        ContentTypes.Add(".mp4", "video/mp4")
        ContentTypes.Add(".wmv", "video/x-ms-wmv")
        ContentTypes.Add(".mov", "video/quicktime")
        '(APPLICATION) Non-standard
        ContentTypes.Add(".pdf", "application/pds")
        ContentTypes.Add(".swf", "aplication/x-shockwave-flash")
    End Sub

    Private Function ParseQuery(ByVal queryset As String) As Dictionary(Of String, String)
        Dim FinQu As New Dictionary(Of String, String)
        If queryset.Length > 0 Then
            For Each qSet As String In queryset.Substring(1).Split("&")
                Dim sA() As String = qSet.Split("=")
                FinQu.Add(sA(0), sA(1))
            Next
        End If
        Return FinQu
    End Function

    Private Sub StartServer()
        Try
            Dim machineName As String = System.Environment.MachineName
            VariableValues.Add("port", PORT)
            VariableValues.Add("computer", machineName)
            theService = HttpUtility.UrlEncode(SERVERNAME)

            WriteContentTypes()

            With listener
                .Prefixes.Add(String.Format("https://*:{0}/", PORT.ToString))
                .Prefixes.Add("http://127.0.0.1:" & PORT.ToString & "/")
                .Start()
            End With

            Dim context As HttpListenerContext
            Dim path As String


            While listener.IsListening
                context = listener.GetContext
                path = context.Request.Url.AbsolutePath.ToLower
                Dim query As Dictionary(Of String, String) = ParseQuery(context.Request.Url.Query)
                If path = "/" Then
                    Select Case CurrentApplicationSituation
                        Case ApplicationSituation.Idle

                        Case ApplicationSituation.Login
                            SendPage(context.Response, My.Computer.FileSystem.CurrentDirectory & "/MobilePandoraConnection/login.html", ".html")
                        Case ApplicationSituation.TrackPage
                            SendPage(context.Response, My.Computer.FileSystem.CurrentDirectory & "/MobilePandoraConnection/track.html", ".html")
                    End Select
                ElseIf path = "/inject" Then
                    SendPage(context.Response, My.Computer.FileSystem.CurrentDirectory & "/MobilePandoraConnection/PandoraMediaServer.js", ".js")
                Else
                    SendPage(context.Response, My.Computer.FileSystem.CurrentDirectory & "/MobilePandoraConnection" & path, path.Substring(path.IndexOf(".")).ToLower())
                End If
            End While

            With listener
                .Stop()
                .Close()
            End With
        Catch ex As Exception
            MsgBox(ex.ToString())
        End Try
    End Sub

    Private Sub SendPage(ByVal response As HttpListenerResponse, ByVal Location As String, ByVal extension As String)

        With response
            .ContentType = ContentTypes(extension)
            .ContentEncoding = Encoding.UTF8

            Try
                Dim cont() As Byte = System.Text.Encoding.ASCII.GetBytes(page)
                Else
                    cont = My.Computer.FileSystem.ReadAllBytes(Location)
                End If
                .OutputStream.Write(cont, 0, cont.LongLength)
                .OutputStream.Flush()
            Catch ex As Exception
                MsgBox("Server Error: " & ex.ToString)
            Finally
                Try
                    .Close()
                Catch ex As Exception
                End Try
            End Try
        End With

    End Sub

    Private Sub MainWindow_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'Stupid Server likes to keep everything running - kill that sucka'
        Process.GetCurrentProcess().Kill()
    End Sub

    Private Sub SystemPanel_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
        'Start server in new thread to prevent an un-reponsive form
        ServerThread = New Threading.Thread(AddressOf StartServer)
        ServerThread.Start()
    End Sub

End Class

If anything doesn’t work (such as, if you tried to copy and paste it straight in for testing), I probably just made a mistake while I was taking some of the unessential code out.

And by-the-way:
– My Firewall is not running

EDIT FOR STEVEDOG

I’ve made these the two prefixes:

.Prefixes.Add(String.Format("https://*:{0}/", PORT.ToString))
.Prefixes.Add(String.Format("http://*:{0}/", PORT.ToString))

Now I get an error every time when it tries to apply the prefixes:

Failed to listen on prefix ‘https://*:8002/’ because it conflicts with an existing registration on the machine.

I’ve checked all the ports that are listening and 8002 is still open…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:21:44+00:00Added an answer on June 5, 2026 at 6:21 am

    You can’t listen on IP address 127.0.0.1. You need to actually listen on your real IP address. Listening on 127.0.0.1 will only receive messages that are sent specifically to the loop-back address.

    Also, you can’t listen to both http and https on the same port and IP address using the HttpListener. See this link for more info:

    .NET HttpListener: when registering both HTTP & HTTPS I get "conflicts with an existing registration on the machine"

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.