vb.net - Why isn't my server accessible outside of my computer? -


i've created http server in vb.net. i've used same "template", guess say, every project requiring http server (quite few recently). problem is, 1 i'm working requires computers on lan able connect it. can access server directly computer though using: http://127.0.0.1:8002/. here 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 applicationsituation = applicationsituation.idle      private listener new httplistener     private theservice string      private const port integer = 8002     private const servername string = "poptimas"      private contenttypes new dictionary(of string, string)      private serverthread threading.thread      private sub writecontenttypes()         '(text) human-readable text , 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 string) dictionary(of string, string)         dim finqu new dictionary(of string, string)         if queryset.length > 0             each qset string in queryset.substring(1).split("&")                 dim sa() string = qset.split("=")                 finqu.add(sa(0), sa(1))             next         end if         return finqu     end function      private sub startserver()         try             dim machinename string = system.environment.machinename             variablevalues.add("port", port)             variablevalues.add("computer", machinename)             theservice = httputility.urlencode(servername)              writecontenttypes()              listener                 .prefixes.add(string.format("https://*:{0}/", port.tostring))                 .prefixes.add("http://127.0.0.1:" & port.tostring & "/")                 .start()             end              dim context httplistenercontext             dim path string               while listener.islistening                 context = listener.getcontext                 path = context.request.url.absolutepath.tolower                 dim query dictionary(of string, string) = parsequery(context.request.url.query)                 if path = "/"                     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"                     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              listener                 .stop()                 .close()             end         catch ex exception             msgbox(ex.tostring())         end try     end sub      private sub sendpage(byval response httplistenerresponse, byval location string, byval extension string)          response             .contenttype = contenttypes(extension)             .contentencoding = encoding.utf8              try                 dim cont() 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 exception                 msgbox("server error: " & ex.tostring)                             try                     .close()                 catch ex exception                 end try             end try         end      end sub      private sub mainwindow_formclosing(sender object, e system.windows.forms.formclosingeventargs) handles me.formclosing         'stupid server likes keep running - kill sucka'         process.getcurrentprocess().kill()     end sub      private sub systempanel_shown(sender object, e system.eventargs) handles me.shown         'start server in new thread prevent un-reponsive form         serverthread = new threading.thread(addressof startserver)         serverthread.start()     end sub  end class 

if doesn't work (such as, if tried copy , paste straight in testing), made mistake while taking of unessential code out.

and by-the-way: - firewall not running

edit stevedog

i've made these 2 prefixes:

.prefixes.add(string.format("https://*:{0}/", port.tostring)) .prefixes.add(string.format("http://*:{0}/", port.tostring)) 

now error every time when tries apply prefixes:

failed listen on prefix 'https://*:8002/' because conflicts existing registration on machine.

i've checked ports listening , 8002 still open...

you can't listen on ip address 127.0.0.1. need listen on real ip address. listening on 127.0.0.1 receive messages sent loop-back address.

also, can't listen both http , https on same port , ip address using httplistener. see link more info:

.net httplistener: when registering both http & https "conflicts existing registration on machine"


Comments