ConnectivityClient

interface ConnectivityClient

Interface for connectivity clients. This should be implemented for every supported communications channel.

This provides the client side of a client-server relationship. Zero or more services can be provided by the server side. The client side can subscribe to these services by a ServiceUuid. Every communication service has an associated ServiceUuid, which is unique for that service and is provided as part of the service definition. That same ID should be used here.

For every subscribed service the client can receive connection state information as well as messages through the ConnectivityClientServiceListener interface. It can also send messages for specific services to the server using sendMessage.

Note: That a server can have multiple clients connected for one service, but a client can only be connected to one server.

Note: On this level there is no persistence between connections. When a connection is lost, no state is maintained and it needs to be fully reinitialized when it is reconnected.

Functions

Link copied to clipboard
abstract fun close()

Closes the client connection and frees all its resources. The client should not be used anymore after this call. After this no more calls will be made to any listeners.

Link copied to clipboard
abstract fun registerClientListener(listener: ConnectivityClientListener)

Register the specified listener.

Link copied to clipboard
abstract suspend fun sendMessage(    serviceConnectionId: ServiceConnectionId,     serviceUuid: ServiceUuid,     data: ByteArray): Boolean

Sends a message with the specified data to the connection with the specified serviceConnectionId for the service with the specified serviceUuid. Returns true when the message is successfully send, false when close was already called or there was no connection at the time.

Link copied to clipboard
abstract suspend fun subscribeToService(serviceUuid: ServiceUuid, listener: ConnectivityClientServiceListener): Boolean

Subscribes to the service with the specified serviceUuid. The specified listener will receive events for the service. Returns true on success, false if the service was already subscribed or if close was already called.

Link copied to clipboard
abstract fun unregisterClientListener(listener: ConnectivityClientListener)

Unregister the specified listener.

Link copied to clipboard
abstract suspend fun unsubscribeFromService(serviceUuid: ServiceUuid): Boolean

Unsubscribes from the service with the specified serviceUuid. Returns true on success, false if the service was not subscribed.