NWTCPSocket
public class NWTCPSocket: NSObject, RawTCPSocketProtocol
The TCP socket build upon NWTCPConnection.
Warning
This class is not thread-safe.-
The
RawTCPSocketDelegateinstance.Declaration
Swift
weak open var delegate: RawTCPSocketDelegate? -
If the socket is connected.
Declaration
Swift
public var isConnected: Bool -
The source address.
Note
Always returnsnil.Declaration
Swift
public var sourceIPAddress: IPAddress? -
The source port.
Note
Always returnsnil.Declaration
Swift
public var sourcePort: Port? -
The destination address.
Note
Always returnsnil.Declaration
Swift
public var destinationIPAddress: IPAddress? -
The destination port.
Note
Always returnsnil.Declaration
Swift
public var destinationPort: Port? -
Connect to remote host.
Throws
Never throws.
Declaration
Swift
public func connectTo(host: String, port: Int, enableTLS: Bool, tlsSettings: [AnyHashable: Any]?) throwsParameters
hostRemote host.
portRemote port.
enableTLSShould TLS be enabled.
tlsSettingsThe settings of TLS.
-
Disconnect the socket.
The socket will disconnect elegantly after any queued writing data are successfully sent.
Declaration
Swift
public func disconnect() -
Disconnect the socket immediately.
Declaration
Swift
public func forceDisconnect() -
Send data to remote.
Warning
This should only be called after the last write is finished, i.e.,delegate?.didWriteData()is called.Declaration
Swift
public func write(data: Data)Parameters
dataData to send.
-
Read data from the socket.
Warning
This should only be called after the last read is finished, i.e.,delegate?.didReadData()is called.Declaration
Swift
public func readData() -
Read specific length of data from the socket.
Warning
This should only be called after the last read is finished, i.e.,delegate?.didReadData()is called.Declaration
Swift
public func readDataTo(length: Int)Parameters
lengthThe length of the data to read.
-
Read data until a specific pattern (including the pattern).
Warning
This should only be called after the last read is finished, i.e.,delegate?.didReadData()is called.Declaration
Swift
public func readDataTo(data: Data)Parameters
dataThe pattern.
-
Read data until a specific pattern (including the pattern).
Warning
This should only be called after the last read is finished, i.e.,delegate?.didReadData()is called.Declaration
Swift
public func readDataTo(data: Data, maxLength: Int)Parameters
dataThe pattern.
maxLengthThe max length of data to scan for the pattern.
-
Undocumented
Declaration
Swift
public class NWTCPSocket: NSObject, RawTCPSocketProtocol -
Undocumented
Declaration
Swift
public class NWTCPSocket: NSObject, RawTCPSocketProtocol
View on GitHub
NWTCPSocket Class Reference