TUNTCPSocket

public class TUNTCPSocket: RawTCPSocketProtocol, TSTCPSocketDelegate

The TCP socket build upon TSTCPSocket.

Warning

This class is not thread-safe.
  • Initailize an instance with TSTCPSocket.

    Declaration

    Swift

    public init(socket: TSTCPSocket)

    Parameters

    socket

    The socket object to work with.

  • The RawTCPSocketDelegate instance.

    Declaration

    Swift

    public weak var delegate: RawTCPSocketDelegate?
  • If the socket is connected.

    Declaration

    Swift

    public var isConnected: Bool
  • The source address.

    Declaration

    Swift

    public var sourceIPAddress: IPAddress?
  • The source port.

    Declaration

    Swift

    public var sourcePort: Port?
  • The destination address.

    Declaration

    Swift

    public var destinationIPAddress: IPAddress?
  • The destination port.

    Declaration

    Swift

    public var destinationPort: Port?
  • TUNTCPSocket cannot connect to anything actively, this is just a stub method.

    Throws

    Never throws anything.

    Declaration

    Swift

    public func connectTo(host: String, port: Int, enableTLS: Bool, tlsSettings: [AnyHashable: Any]?) throws

    Parameters

    host

    host

    port

    port

    enableTLS

    enableTLS

    tlsSettings

    tlsSettings

  • 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 local.

    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

    data

    Data 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

    length

    The 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

    data

    The 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

    data

    The pattern.

    maxLength

    Ignored since GCDAsyncSocket does not support this. The max length of data to scan for the pattern.

  • Declaration

    Swift

    open func localDidClose(_ socket: TSTCPSocket)
  • Declaration

    Swift

    open func socketDidReset(_ socket: TSTCPSocket)
  • Declaration

    Swift

    open func socketDidAbort(_ socket: TSTCPSocket)
  • Declaration

    Swift

    open func socketDidClose(_ socket: TSTCPSocket)
  • Declaration

    Swift

    open func didReadData(_ data: Data, from: TSTCPSocket)

    Parameters

    data
    from
  • Declaration

    Swift

    open func didWriteData(_ length: Int, from: TSTCPSocket)

    Parameters

    length
    from