Jon M. Hanson
Jon M. Hanson

Reputation: 30

Performing TCP/IP network I/O in Swift

I'm writing a Swift application under OS X that needs to do TCP/IP port-level network I/O (optionally with SSL/TLS). I've done a lot of searching and it looks like NSStream is the way to go for this. However, the class reference for NSStream says that the class method getStreamsToHost() is deprecated as of OS X 10.10, which appears to be what I need to use, but doesn't say what replaces it. Does anyone know what mechanism I need to use in order to connect to a host on a specific port (no, not 80) in order to do the I/O in Swift under OS X?

Upvotes: 0

Views: 594

Answers (1)

Eric Aya
Eric Aya

Reputation: 70098

It has been replaced with getStreamsToHostWithName.

Example:

var input: AutoreleasingUnsafeMutablePointer<NSInputStream?> = nil
var output: AutoreleasingUnsafeMutablePointer<NSOutputStream?> = nil

NSStream.getStreamsToHostWithName(YOUR_HOST, port: YOUR_PORT, inputStream: input, outputStream: output)

Upvotes: 2

Related Questions