ZitiConnection

@objc
public class ZitiConnection : NSObject, ZitiUnretained

Create ZitiConnections from an instance of Ziti and use to commuicate with services over a Ziti network

  • Connection callback

    This callback is invoked after dial(_:_:_:) or accept(_:_:) is completed. The result of the function may be an error condition so it is important to verify the status code in this callback. If successful the status will be set to ZITI_OK

    Declaration

    Swift

    public typealias ConnCallback = (_ conn: ZitiConnection, _ status: Int32) -> Void

    Parameters

    conn

    reference to ZitiConnection

    status

    ZITI_OK on success, else Ziti error code

  • Listen callback

    This callback is invoked after listen(_:_:_:) and is aliased to ConnCallback as a convenience for human readability

    Declaration

    Swift

    public typealias ListenCallback = ConnCallback
  • Data callback

    This callback is invoked when data arrives from Ziti, either as a response from dial(_:_:_:) or from accept(_:_:) Return value should indicate how much data was consumed by the application. This callback will be called again at some later time and as many times as needed for application to accept the all of the data

    Declaration

    Swift

    public typealias DataCallback = (_ conn: ZitiConnection, _ data: Data?, _ status: Int) -> Int

    Parameters

    conn

    the connection

    data

    the incoming data

    status

    size of the data or a Ziti error code, ZITI_EOF when connection has closed

  • Client callback

    This callback is invoked when a client connects to the service specified in listen(_:_:_:) call. The result of the status may be an error condition so it is important to verify the status code in this callback. If successful the status will be set to ZITI_OK

    Generally this callback is used for any preparations necessary before accepting incoming data from the Ziti network.

    Declaration

    Swift

    public typealias ClientCallback = (_ server: ZitiConnection, _ client: ZitiConnection, _ status: Int32) -> Void

    Parameters

    server

    server connection

    client

    client connection, generally used to accept()the connection in this callback

    status

    ZITI_OK or error code

  • Write callback

    This callback is invoked after a call the write(_:_:) completes. The result of the write(_:_:) may be an error condition so it is important to verify the provided status code in this callback.

    This callback is often used to free or reinitialize the buffer associated with the write(_:_:). It is important to not free this memory until after data has been written to the wire else the results of the write operation may be unexpected.

    Declaration

    Swift

    public typealias WriteCallback = (_ conn: ZitiConnection, _ status: Int) -> Void

    Parameters

    status

    amount of data written or Ziti error code

  • Close callback

    This callback is invoked after a call the close(_:) completes.

    Declaration

    Swift

    public typealias CloseCallback = () -> Void

    Parameters

    status

    amount of data written or Ziti error code

  • Established a connection to a Ziti service.

    Before any bytes can be sent over a Zitiservice a connection must be established. This method will attempt to establish a connection by dialiing the service with the given name. The result of the dial() attempt is included in the specified ConnCallback.

    If the dial succeeds, the provided DataCallback is invoked to handle data returned from the service. If the dial fails, only the ConnCallback will be invoked with the corresponding error code

    Declaration

    Swift

    @objc
    public func dial(_ service: String, _ onConn: @escaping ConnCallback, _ onData: @escaping DataCallback)

    Parameters

    service

    name of the service to dial

    onConn

    callback invoked after dial attempt completes

    onData

    callback invoked after a successful dial attempt with data received over the connection

  • Start accepting Ziti client connections

    This function is invoked to tell the Ziti to accept connections from other Ziti clients for the provided service name.

    Declaration

    Swift

    @objc
    public func listen(_ service: String, _ onListen: @escaping ListenCallback, _ onClient: @escaping ClientCallback)

    Parameters

    service

    name of the service to be hosted

    onListen

    callback invoked indicating success or failure of listen attempt

    onClient

    callback invoked when client attempts to dial this service

  • Completes a client connection

    After a client connects to a hosted Ziti service this method is invoked to finish connection establishment, establishing the callbacks necessary to send data to the connecting client or to process data sent by the client.

    Declaration

    Swift

    @objc
    public func accept(_ onConn: @escaping ConnCallback, _ onData: @escaping DataCallback)

    Parameters

    onConn

    invoked when accept completes indicating status of the attempt

    onData

    invoked each time the client sends data

  • Get the identity of the client that initiated the Ziti connection

    Declaration

    Swift

    @objc
    public func getSourceIdentity() -> String

    Return Value

    Source ID or empty String

  • Send data to the connection peer

    Declaration

    Swift

    @objc
    public func write(_ data: Data, _ onWrite: @escaping WriteCallback)

    Parameters

    data

    the data to send

    onWrite

    callback invoked after the write completes

  • Close this connection

    When no longer needed the connection should be closed to gracefully disconnect. This method should be invoked after any status is returned which indicates an error situation.

    Declaration

    Swift

    @objc
    public func close(_ onClose: CloseCallback? = nil)

    Parameters

    onClose

    called when connection is completely closed