1

我正在尝试在我的 J2ME 应用程序(使用 JSR-082 API)和我用 Python 编写的桌面应用程序(使用 pybluez 蓝牙 API)之间建立蓝牙连接。但是,我找不到合适的蓝牙通信协议来配对它们。

在pybluez中,连接服务器的方式如下:

addr, port = "01:23:45:67:89:AB", 1
sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((addr, port))

但是在 JSR-082 蓝牙 API 中,创建服务器的方式如下:

StreamConnectionNotifier connectionNotifier =
    (StreamConnectionNotifier) Connector.open("btspp://localhost:" + 
    "0000000000000000000000000000ABCD;name=JSR82_ExampleService");
streamConnection = connectionNotifier.acceptAndOpen();

或如下:

L2CAPConnectionNotifier connectionNotifier = 
    (L2CAPConnectionNotifier) Connector.open("btl2cap://localhost:" + 
    "0000000000000000000000000000ABCD;name=JSR82_ExampleService");
streamConnection = connectionNotifier.acceptAndOpen();

在 pybluez API 中我们使用端口号,在 JSR-082 API 中我们使用 URL。那我该如何建立蓝牙连接呢?有没有办法使用 JSR-082 API 中的端口号创建服务器?

4

1 回答 1

1

使用 JSR-82,您可以创建基于 UUID 的服务器。您需要执行 SDP 搜索以确定远程服务的“端口”(实际上是 RFCOMM 的通道号或 L2CAP 的 PSM)。因此,在 pybluez 中,您将调用(如此bluetooth.find_service()所示),检查返回的每个服务,然后选择具有匹配 UUID(bluez 中的“service-id”)的服务。

于 2011-01-04T05:34:08.020 回答