I'm trying to build a handshake between an iOS app and a Socketio server based off of this tutorial: Teehan+Lax
The issue I'm having is that a connection is never opened properly, which I think is because the Handshake + token aren't being generated properly:
func initHandshake() {
let time:NSTimeInterval = NSDate().timeIntervalSince1970 * 1000
println(time)
var timeString = "\(time)"
var formattedTime = timeString.stringByReplacingOccurrencesOfString(".", withString: "-", options: NSStringCompareOptions.LiteralSearch)
println(formattedTime)
var endpoint = "http://\(server)/socket.io/1?t=\(formattedTime)"
println(endpoint)
var handshakeTask:NSURLSessionTask = session!.dataTaskWithURL(NSURL(fileURLWithPath: endpoint)!, completionHandler: { (data:NSData!, response:NSURLResponse!, error:NSError!) in
if !(error != nil) {
let stringData:NSString = NSString(data: data, encoding: NSUTF8StringEncoding)!
let handshakeToken:NSString = stringData.componentsSeparatedByString(":")[0] as NSString
println("HANDSHAKE \(handshakeToken)")
self.socketConnect(handshakeToken)
}
if ((error) != nil) {
println("Didn't connect. Why?")
}
})
handshakeTask.resume()
}
You can see a few attempts I made in the code to match the endpoint URL with the string that Socketio returns, but no dice. It still doesn't connect.
I haven't written any Swift before so I'm fairly lost about what this code is actually trying to grab:
var handshakeTask:NSURLSessionTask = session!.dataTaskWithURL(NSURL(fileURLWithPath: endpoint)!, completionHandler: { (data:NSData!, response:NSURLResponse!, error:NSError!) in
Anyone have any ideas?