ioswifigcdwebserver

GDCWebserver serverURL is null when wifi is turned off


I am not accessing from a different network. I am just trying to serve files for a hybrid app.

Just running the basic server works as intended when I am connected to a wifi network using the code below:

  let webServer = GCDWebServer()

    webServer.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self, processBlock: {request in
        return GCDWebServerDataResponse(HTML:"<html><body><p>Hello World</p></body></html>")

    })

    webServer.startWithPort(8080, bonjourName: "GCD Web Server")

    print("Visit \(webServer.serverURL) in your web browser")

logs:

Visit http://192.168.1.132:8080/ in your web browser

When I drop wifi and start the app and server I get:

GCDWebServer started on port 8080 and reachable at (null)


Solution

  • serverUrl is null, but good ol local host works :

    localhost://

    Also available was the bonjour service url that is served up

    func webServerDidCompleteBonjourRegistration(server: GCDWebServer!) {
    
        if(self.serverURL == nil){
            self.serverURL=self.webServer!.bonjourServerURL
            print(self.serverURL)
            self.initWebView()
        }
    
    
    }
    

    that got things running locally with wifi off.