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