TCPSocket
open class TCPSocket : POSIXSocket, CustomStringConvertible
Socket: Endpoint of a TCP/IP connection.
Data can be read from the socket with the input stream provided as a property of a socket instance.
Data can be written to the socket with the output stream provided as a property of a socket instance.
-
Host address of the peer.
Only used for outgoing connections.
Declaration
Swift
open fileprivate(set) var hostAddress: String?
-
Indicates, if non-blocking I/O is used or en-/disables non-blocking I/O.
If non-blocking I/O is used, reading from the socket may not return any data and writing may fail because it would otherwise block the current thread.
In this case, a .WouldBlock or .Again IOError will be thrown.
The operation must be repeated until it was successful.
For read operations, the delegate of the stream should be used for efficient reading.
Declaration
Swift
open var nonblocking: Bool
Parameters
new
Specifies, if the socket should be non-blocking or not. A value of true sets the socket to nonblocking mode, false to blocking mode.
Return Value
true, if the socket is nonblocking, false if it is blocking.
-
The input stream of the socket.
Incoming data can be read from it.
If the socket uses non-blocking I/O, a delegate should be used to receive notifications about incoming data.
Declaration
Swift
open fileprivate(set) var inputStream: InputStream!
-
The output stream of the socket.
Can write data to the socket.
If the socket uses non-blocking I/O, the operation may fail and a .WouldBlock or .Again IOError may be thrown. The operation must then be tried again.
Declaration
Swift
open fileprivate(set) var outputStream: OutputStream!
-
Returns the IP address of the peer to which this socket is connected to.
The result is a IPv4 or IPv6 address depending on the IP protocol version used.
Declaration
Swift
open var peerIP:String?
-
Checks if the socket is open.
The socket is open if at least one of the streams associated with this socket is open.
Declaration
Swift
open var open:Bool
-
A textual representation of self.
Declaration
Swift
open var description: String
-
Initializes the socket and connects to the address specified in
host
.The
host
address must be an IPv4 address.Throws
A SocketError if the socket could not be connected.
Declaration
Swift
public convenience init(ipv4host host: String, port: UInt16) throws
Parameters
host
IPv4 peer address string
port
Port to which the socket should connect.
-
Initializes a socket with a given host address and TCP port
The socket will automatically connect to the given host.
Declaration
Swift
public init?(address: String, port: UInt16) throws
Parameters
address
The host address of the server to connect to.
port
The TCP port on which the server should be connected.
-
Manually closes the socket and releases any ressources related to it.
Subsequent calls of the streams’ read and write functions will fail.
Declaration
Swift
open func close()
-
Checks the status of the streams which read and write from and to this socket.
If both streams are closed, the socket will be closed.
Declaration
Swift
open func checkStreams()