         
         return chatResults
     }
+
+    // MARK: - Private Functions
+    func startPingTimer() {
+        self.pingTimer = NSTimer.scheduledTimerWithTimeInterval(
+            60, target: self, selector: Selector("sendPing:"), userInfo: nil, repeats: true)
+    }
+
+    func stopPingTimer() {
+        self.pingTimer?.invalidate()
+        self.pingTimer = nil
+    }
+
+    func sendPing(timer: NSTimer) {
+        sendMessage("<ping>PING</ping>")
+    }
 }

    
    var inputStream: NSInputStream?
    var outputStream: NSOutputStream?
    
    var parsingString: NSString = ""
    

        let message = "<thread thread=\"\(server.thread)\" res_from=\"-\(resFrom)\" version=\"20061206\"/>"
        self.sendMessage(message)
        
        self.startPingTimer()

        while self.inputStream != nil {
            self.runLoop.runUntilDate(NSDate(timeIntervalSinceNow: NSTimeInterval(1)))
        }
