 
 import Foundation
 
+extension String {
+    private var length:Int {
+        return Array(self).count
+    }
+}
+
 private enum PacketType: String {
     case OPEN = "0"
     case CLOSE = "1"

        }
    }
    
    func handlePollingResponse(str:String) {
        // TODO add polling
    }
    
    func parseWebSocketMessage(message:AnyObject?) {
        if let data = message as? NSData {
            // Strip off message type
            self.client.parseSocketMessage(data.subdataWithRange(NSMakeRange(1, data.length - 1)))

                if self == nil {
                    return
                } else if err != nil || data == nil {
                    println(err)
                    self?.handlePollingFailed()
                    return
                    
                }
                
                if let dataString = NSString(data: data, encoding: NSUTF8StringEncoding) {
