RawTCPSocketProtocol

public protocol RawTCPSocketProtocol : class

The raw socket protocol which represents a TCP socket.

Any concrete implementation does not need to be thread-safe.

Warning

It is expected that the instance is accessed on the specific queue only.
  • The RawTCPSocketDelegate instance.

    Declaration

    Swift

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

    Declaration

    Swift

    var isConnected: Bool
  • The source address.

    Declaration

    Swift

    var sourceIPAddress: IPAddress?
  • The source port.

    Declaration

    Swift

    var sourcePort: Port?
  • The destination address.

    Declaration

    Swift

    var destinationIPAddress: IPAddress?
  • The destination port.

    Declaration

    Swift

    var destinationPort: Port?
  • Connect to remote host.

    Throws

    The error occured when connecting to host.

    Declaration

    Swift

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

    Parameters

    host

    Remote host.

    port

    Remote port.

    enableTLS

    Should TLS be enabled.

    tlsSettings

    The settings of TLS.

  • Disconnect the socket.

    The socket should disconnect elegantly after any queued writing data are successfully sent.

    Note

    Usually, any concrete implementation should wait until any pending writing data are finished then call forceDisconnect().

    Declaration

    Swift

    func disconnect()
  • Disconnect the socket immediately.

    Note

    The socket should disconnect as soon as possible.

    Declaration

    Swift

    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

    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

    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

    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

    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

    func readDataTo(data: Data, maxLength: Int)

    Parameters

    data

    The pattern.

    maxLength

    The max length of data to scan for the pattern.