Socket
public protocol Socket : class
The Socket protocol provides an interface for a network socket, which is an endpoint in network communication.
The user can communicate through the streams provided by the socket. Incoming data can be retrieved through the input stream and data can be written to the network with the output stream.
-
Host address of the peer.
Only used for outgoing connections.
Declaration
Swift
var hostAddress: String?
-
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
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
var outputStream: OutputStream!
-
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
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.
-
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
var open:Bool
-
Manually closes the socket and releases any ressources related to it.
Subsequent calls of the streams’ read and write functions will fail.
Declaration
Swift
func close()
-
checkStreams()
Default implementationChecks the status of the streams which read and write from and to this socket.
If both streams are closed, the socket will be closed.
Default Implementation
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
func checkStreams()