-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrfcomm-client.c
More file actions
33 lines (26 loc) · 752 Bytes
/
rfcomm-client.c
File metadata and controls
33 lines (26 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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, status;
char dest[18] = "01:23:45:67:89:AB";
// 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 = 1;
str2ba(dest, &addr.rc_bdaddr);
// connect to server
status = connect(s, (struct sockaddr*)&addr, sizeof(addr));
// send a message
if (0 == status) {
status = send(s, "hello!", 6, 0);
}
if (status < 0) perror ("uh oh");
close(s);
return 0;
}