简体   繁体   中英

Transport endpoint is not connected bluez

Transport endpoint is not connected

#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;
}

i used this code from http://people.csail.mit.edu/albert/bluez-intro/x502.html . i modified it to trnsfer a large file of 8 mb by bluetooth by using file functions of c. i am getting the error "transport endpoint is not connected" what to do?

In the code you have specified channel number as 1 addr.rc_channel = (uint8_t) 1; But channel number 1 stands for SDP which cannot be used for file transfer If your remote device mobile or any other device and if it supports OPP then you can specify channel number as 9 addr.rc_channel = (uint8_t) 9; and you can see file transfer successful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM