带pythonbluez clien的android蓝牙服务器插座

2024-10-01 17:31:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将我的笔记本电脑(作为客户端)连接到我的android手机(作为监听器),在笔记本电脑上使用pythonbluez,在手机上使用android蓝牙API。在

我的手机使用以下代码:

BluetoothServerSocket tmp = badapter.listenUsingRfcommWithServiceRecord(
    badapter.getName(), MY_UUID);
BluetoothServerSocket bserversocket = tmp;
if(bserversocket != null)
{
    BluetoothSocket acceptsocket = bserversocket.accept(timeout);   
}
//timeout is set to about 15 sec
if(acceptsocket != null)
{
    out.append("got the connection...\n");   
}

在python中为我的笔记本客户端提供了以下内容:

^{pr2}$

监听器在没有确认来自笔记本电脑的任何连接的情况下超时,而发送者继续在不同端口上打印“Connected”。在

问题是,我不知道也无法设置android手机正在监听的端口/通道,而且我需要填写端口号作为“connect”的第二个参数(此片段中为2)。在

请帮帮我-我现在唯一的目标是让电话确认连接尝试。在


Tags: 端口客户端iftimeoutnulltmp笔记本电脑android

热门问题