c++ - 使用套接字 rfcomm 的蓝牙连接

标签 c++ c linux bluetooth

我有两个蓝牙设备,我正在尝试建立两个 rfcomm 连接,每个设备一个连接。

我正在使用 bluez rfcomm 套接字

addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 1;
str2ba( dest, &addr.rc_bdaddr );

// connect to server
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// set disconnect timeout to 2sec
struct timeval tv;
tv.tv_sec = 2;
setsockopt(s, SOL_SOCKET, SO_RCVTIMEO,(struct timeval *)&tv,sizeof(struct timeval));

// make connection
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));

如何选择设备进行连接?

最佳答案

我相信 bluez 最多支持 16 个加密狗。

您可能对此项目中的代码感兴趣: http://diy-machine.blogspot.com/

关于c++ - 使用套接字 rfcomm 的蓝牙连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5474457/

相关文章:

c++ - 解析在 XML 中的 C/C++ 头文件中定义的嵌套结构/union

c - 使用 getline 当行为空时退出循环

PHP 在 proc_open() 之后没有立即返回

c++ - xterm 窗口无法在 Linux 上保持,它出现然后消失得非常快

c - C 字数统计程序

c++ - 一种使用boost和c++列出目录和子目录下所有文件的方法

c - 没有与 GCC 的内存对齐

linux - 在 linux 中使用 bash 脚本通过轮询按键来启动和停止 tail

c++ - 我误用了继承权吗?

c++ - QThread - 使用槽 quit() 退出线程