Created
June 24, 2015 13:57
-
-
Save Alexander-Ignition/a6e72e979b6f86fa2836 to your computer and use it in GitHub Desktop.
NSURLSessionStreamTask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Asynchronous read | |
let task = NSURLSession.sharedSession().streamTaskWithHostName("chat.example.com", port: 5555)! | |
task.resume() | |
task.readDataOfMinLength(16384, maxLength:65536, timeout: 30.0) { | |
(data: NSData?, eof: Bool, error: NSError?) in | |
// | |
} | |
// Asynchronous write | |
let task = NSURLSession.sharedSession().streamTaskWithHostName("chat.example.com", port: 5555)! | |
task.resume() | |
let data: NSData = //... | |
task.writeData(data, timeout: 30.0) { | |
(error: NSError?) in | |
// | |
} | |
// Enabling TLS | |
let task = NSURLSession.sharedSession().streamTaskWithHostName("chat.example.com", port: 5555)! | |
task.startSecureConnection() | |
task.resume() | |
let data: NSData = // ... | |
task.writeData(data, timeout: 30.0) { | |
(error: NSError?) in | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment