Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9554687
  • 博文数量: 1760
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20191
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1760)

文章存档

2025年(9)

2024年(27)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: Windows平台

2016-12-07 15:02:38


点击(此处)折叠或打开

  1. //client.c

  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <sys/socket.h>
  6. #include <bluetooth/bluetooth.h>
  7. #include <bluetooth/rfcomm.h>

  8. int main( int argc , char **argv)
  9. {
  10.    struct sockaddr_rc addr={0};
  11.    int s,status;
  12.    char buf[1024];
  13.    char dst[] = "58:88:97:4F:2C:41";
  14.    time_t t;

  15.    // a l l o c a t e a s oc k e t
  16.    s=socket(PF_BLUETOOTH,SOCK_STREAM,BTPROTO_RFCOMM);
  17.    if(s<0) {
  18.        perror("create socket error");
  19.        exit(1);
  20.    }

  21.    // s e t the conne c t ion parameter s (who to connect to )
  22.    addr.rc_family=AF_BLUETOOTH;
  23.    addr.rc_channel=(uint8_t)1;
  24.    str2ba(dst,&addr.rc_bdaddr);
  25.    // connect to s e r v e r
  26.    printf("connectting...\n");
  27.    status=connect(s,(struct sockaddr *)&addr,sizeof(addr));

  28.    // send a message
  29.    if(status==0) {
  30.      printf("scuess!\n");

  31.      do{
  32.         gets(buf);
  33.         time(&t);
  34.         sprintf(buf, "{\"ssid\":\"%s\", \"psw\":\"%s\", \"timestamp\":%ld}","360ND", "00000000", t);
  35.    // sprintf(buf, "{\"ssid\":\"%s\", \"psw\":\"%s\", \"timestamp\":%ld}","SEC", "sec12345", t);
  36.         printf("[%s]\n", buf);
  37.         status=write(s,buf,strlen(buf));
  38.         if(status<0) perror("uh oh");
  39.      }while(strcmp(buf,"goodbye")!=0);
  40.    }
  41.    else {
  42.      printf("Failed!\n");
  43.    }

  44.    close(s);
  45.    return 0;
  46. }

阅读(1538) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~