Skip to content

Serving

aio_rfcomm.RfcommService

A service published on this computer, listening for devices.

service property

service: UUID

The service's UUID.

name property

name: str

The service's name.

channel property

channel: int

The RFCOMM channel the service is on.

A device that cannot look up the service by its UUID needs this number.

connection_requests

connection_requests() -> ConnectionRequests

Get each device that connects, as it arrives.

async with asyncio.TaskGroup() as group:
    async for request in service.connection_requests():
        group.create_task(talk(request))

Returns:

aio_rfcomm.ConnectionRequests

The devices connecting to a service, one request each.

Made by RfcommService.connection_requests. When Bluetooth stops being usable, the async for loop raises BluetoothUnavailableError.

aio_rfcomm.RfcommConnectionRequest

A device that has connected to a service.

Accept it, or decline it. A request that is neither is hung up on when it is garbage collected, with a ResourceWarning.

info property

The device that connected. Its name may be missing.

accept

accept() -> AbstractAsyncContextManager[RfcommChannel]

Accept the connection.

Returns:

  • AbstractAsyncContextManager[RfcommChannel] –

    An async context manager that gives the channel, and closes it when the block ends. The channel carries on even if the service stops first.

Raises:

  • RuntimeError –

    The request was already accepted or declined.

  • ScopeClosedError –

    The service's block has ended.

  • BluetoothUnavailableError –

    Bluetooth stopped being usable since the request arrived.

decline async

decline() -> None

Turn the device away by hanging up.

The device sees its connection fail, or open and then close at once. This always takes effect, even if it is canceled. It does not raise if hanging up fails. Declining twice does nothing.

Raises:

  • RuntimeError –

    The request was already accepted.