gpt4 book ai didi

c - 传输端点未连接 bluez

转载 作者:太空宇宙 更新时间:2023-11-04 04:51:54 25 4
gpt4 key购买 nike

传输端点未连接

#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>

int main(int argc, char **argv)
{
struct sockaddr_rc addr = { 0 };
int s, i, status;
char dest[18] = "88:53:2E:10:BB:B0";
FILE *ptr1;
char c;
char str[1024];
// allocate a socket
s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

// set the connection parameters (who to connect to)
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 1;
str2ba( dest, &addr.rc_bdaddr );

// connect to server
status = connect(s, (struct sockaddr *)&addr, sizeof(addr));

// send a message
if( status == 0 ) {
ptr1=fopen("//home//aathreya//Desktop//Bluetooth//imudata_acm0.dat","r"); //open file to be read
i=0;
while((c=fgetc(ptr1))!= EOF) //copy 1024 bytes at a time to a string
{
str[i]=c;
i++;
if (i==1024)
{
i=0;
status = write(s, str, 1024);
}
}
status = write(s, str, 1024);
status = write(s, "stop", 4); //flag to stop reading at client
fclose(ptr1);
}

if( status < 0 ) perror("uh oh");

close(s);
return 0;
}

我使用了来自 http://people.csail.mit.edu/albert/bluez-intro/x502.html 的代码.我将其修改为使用 c 的文件功能通过蓝牙传输 8 MB 的大文件。我收到错误消息“传输端点未连接”该怎么办?

最佳答案

在代码中,您已将 channel 号指定为 1地址.rc_channel = (uint8_t) 1;但是 channel 号 1 代表不能用于文件传输的 SDP如果您的远程设备是移动设备或任何其他设备,并且它支持 OPP,那么您可以指定 channel 号为 9地址.rc_channel = (uint8_t) 9;可以看到文件传输成功。

关于c - 传输端点未连接 bluez,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14353046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com