GCDTCPSocket
open class GCDTCPSocket: NSObject, GCDAsyncSocketDelegate, RawTCPSocketProtocol
The TCP socket build upon GCDAsyncSocket.
Warning
This class is not thread-safe.-
Initailize an instance with
GCDAsyncSocket.Declaration
Swift
public init(socket: GCDAsyncSocket? = nil)Parameters
socketThe socket object to work with. If this is
nil, then a newGCDAsyncSocketinstance is created.
-
The
RawTCPSocketDelegateinstance.Declaration
Swift
weak open var delegate: RawTCPSocketDelegate? -
If the socket is connected.
Declaration
Swift
open var isConnected: Bool -
The source address.
Declaration
Swift
open var sourceIPAddress: IPAddress? -
The source port.
Declaration
Swift
open var sourcePort: Port? -
The destination address.
Note
Always returnsnil.Declaration
Swift
open var destinationIPAddress: IPAddress? -
The destination port.
Note
Always returnsnil.Declaration
Swift
open var destinationPort: Port? -
Connect to remote host.
Throws
The error occured when connecting to host.
Declaration
Swift
open func connectTo(host: String, port: Int, enableTLS: Bool = false, tlsSettings: [AnyHashable: Any]? = nil) 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
open func disconnect() -
Disconnect the socket immediately.
Declaration
Swift
open 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
open 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
open 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
open 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
open 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
open func readDataTo(data: Data, maxLength: Int)Parameters
dataThe pattern.
maxLengthIgnored since
GCDAsyncSocketdoes not support this. The max length of data to scan for the pattern.
-
Send data to remote.
Warning
This should only be called after the last write is finished, i.e.,delegate?.didWriteData()is called.Declaration
Swift
func write(data: Data, withTimeout timeout: Double)Parameters
dataData to send.
timeoutOperation timeout.
-
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
func readDataTo(length: Int, withTimeout timeout: Double)Parameters
lengthThe length of the data to read.
timeoutOperation timeout.
-
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
func readDataTo(data: Data, withTimeout timeout: Double)Parameters
dataThe pattern.
timeoutOperation timeout.
-
Connect to remote host.
Throws
The error occured when connecting to host.
Declaration
Swift
func connectTo(host: String, withPort port: Int) throwsParameters
hostRemote host.
portRemote port.
-
Secures the connection using SSL/TLS.
Declaration
Swift
func startTLSWith(settings: [AnyHashable: Any]!)Parameters
tlsSettingsTLS settings, refer to documents of
GCDAsyncSocketfor detail.
-
Undocumented
Declaration
Swift
open class GCDTCPSocket: NSObject, GCDAsyncSocketDelegate, RawTCPSocketProtocol -
Undocumented
Declaration
Swift
open class GCDTCPSocket: NSObject, GCDAsyncSocketDelegate, RawTCPSocketProtocol -
Undocumented
Declaration
Swift
open class GCDTCPSocket: NSObject, GCDAsyncSocketDelegate, RawTCPSocketProtocol -
Undocumented
Declaration
Swift
open class GCDTCPSocket: NSObject, GCDAsyncSocketDelegate, RawTCPSocketProtocol -
Undocumented
Declaration
Swift
open class GCDTCPSocket: NSObject, GCDAsyncSocketDelegate, RawTCPSocketProtocol
View on GitHub
GCDTCPSocket Class Reference