Can't connect to local host

I am testing some tvOS code and it works great on the Simulator however on the Dev Kit running OS beta 2 I am receiving the following error:


2015-09-27 11:10:29.797 RWDevCon[272:46267] SSSQLiteDatabase: Could not open database, resetting: [23, /var/mobile/Library/Cookies/com.apple.itunesstored.2.sqlitedb]

_CFURLRequestCopyStorageSession deprecated

2015-09-27 11:10:29.810 RWDevCon[272:46267] ITML: Setting [1] for Ignore HTTP Cache

2015-09-27 11:10:34.886 RWDevCon[272:46267] ITML: Setting [3] log level

2015-09-27 11:10:34.887 RWDevCon[272:46267] ITML <Error>: Failed to load launch URL with error: Error Domain=NSURLErrorDomain Code=-1004 "Cannot connect to localhost" UserInfo={NSUnderlyingError=0x137d2dee0 {Error Domain=kCFErrorDomainCFNetwork Code=-1004 "Could not connect to the server." UserInfo={NSErrorFailingURLStringKey=http://localhost:9001/js/application.js, NSErrorFailingURLKey=http://localhost:9001/js/application.js, _kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1, NSLocalizedDescription=Could not connect to the server.}}, NSErrorFailingURLStringKey=http://localhost:9001/js/application.js, NSErrorFailingURLKey=http://localhost:9001/js/application.js, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=61, NSLocalizedDescription=Cannot connect to localhost}



Swift Code:

class AppDelegate: UIResponder, UIApplicationDelegate, TVApplicationControllerDelegate {

var window: UIWindow?


var appController: TVApplicationController? /

static let TVBaseURL = "http:/

static let TVBootURL = "\(AppDelegate.TVBaseURL)js/application.js" /


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

window = UIWindow(frame: UIScreen.mainScreen().bounds)

/

let appControllerContext = TVApplicationControllerContext()

/

guard let javaScriptURL = NSURL(string: AppDelegate.TVBootURL) else {

fatalError("unable to create NSURL")

}

appControllerContext.javaScriptApplicationURL = javaScriptURL

appControllerContext.launchOptions["BASEURL"] = AppDelegate.TVBaseURL

/

appController = TVApplicationController(context: appControllerContext, window: window, delegate: self)

return true

}

}



JavaScript/server code:

App.onLaunch = function(options) {


// 1

var alert = createAlert("Welcome to tvOS Programming", "It will be Awesome!"); // leaving 2nd parameter with an empty string

navigationDocument.presentModal(alert);

}


// 2

var createAlert = function(title, description) {


var alertString = `<?xml version="1.0" encoding="UTF-8" ?>

<document>

<alertTemplate>

<title>${title}</title>

<description>${description}</description>

<button><text>OK</text></button>

</alertTemplate>

</document>`


var parser = new DOMParser();

var alertDoc = parser.parseFromString(alertString, "application/xml");


return alertDoc

}



Starting the Server:

> python -m SimpleHTTPServer 9001


NB: Allow Arbitary Loads is set to YES

Answered by decipher21 in 65163022

Our question was answered on Stackoverflow. Hope it helps you as well.

http://stackoverflow.com/questions/32812780/tvos-cannot-connect-to-localhost

I've a smiliar problem with Python SimpleHTTPServer and the ATV-Devkit:

"Failed to load launch URL with error: (null)".


With the Simulator it works fine.

Accepted Answer

Our question was answered on Stackoverflow. Hope it helps you as well.

http://stackoverflow.com/questions/32812780/tvos-cannot-connect-to-localhost

Can't connect to local host
 
 
Q