【问题标题】:Transport endpoint is not connected bluez传输端点未连接 bluez
【发布时间】:2023-10-25 20:47:02
【问题描述】:

传输端点未连接

#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 的大文件。 我收到错误“传输端点未连接” 该怎么办?

【问题讨论】:

  • 我也有同样的问题。我注意到多个writesend 是不可能的。但我找不到解决方案。我现在每次都只是关闭和打开连接。如果这对您来说不是性能问题,那么它可以正常工作。

标签: c endpoint rfcomm transport bluez


【解决方案1】:

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

【讨论】: