ConnectivityServer

interface ConnectivityServer

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

This provides the server 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 well known ServiceUuid. For every service the server provides events that indicate when clients connect, disconnect or send messages using the ConnectivityServerServiceListener. Messages can be send to clients by using the sendMessage method.

Functions

Link copied to clipboard
abstract fun close()

Closes the server and frees all its resources.

Link copied to clipboard
abstract suspend fun provideService(serviceUuid: ServiceUuid, listener: ConnectivityServerServiceListener): Boolean

Starts providing a service with the specified serviceUuid. The specified listener will be called with service events. Returns true on success, false otherwise.

Link copied to clipboard
abstract fun registerServerListener(listener: ConnectivityServerListener)

Registers the specified listener.

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

Sends a messaging containing the specified data for the service with the specified serviceUuid to the client with the specified serviceConnectionId. Returns true when the messages has been successfully send, false otherwise.

Link copied to clipboard
abstract fun unregisterServerListener(listener: ConnectivityServerListener)

Unregisters the specified listener.