- 论坛徽章:
- 0
|
if( send(invoke_service_fd, "069",3,0) < 0 ) //就是这里调用出错
{
perror("send");
exit(1);
}
status = 0;
//在类初始化时有调用如下 connect_server()函数。
socket连接代码如下:
static int connect_server()
{
struct sockaddr_rc addr = { 0 };
//strcpy(dest,svc_addr); //set target device addr
char dest[18] = "00:1F:81:00:04:31"; /* server bt addr */
char buf[1024];
memset(buf,0,sizeof(buf));
// allocate a socket
fd = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
if( fd < 0 )
{
perror("socket");
return -1;
}
// set the connection parameters (who to connect to)
addr.rc_family = AF_BLUETOOTH;
addr.rc_channel = (uint8_t) 1;
str2ba( dest, &addr.rc_bdaddr );
printf("socket created\n");
// connect to server, update status ( global status )
status = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
printf("connect to server status %d\n",status);
if(status != 0)
{
perror("connect");
return -1;
}
else
return 0;
} |
|