0

我有一个使用两台笔记本电脑的实验装置,一台作为发射器,另一台作为接收​​器。发送器根据已配置的不同定时器的时间段,不断地发送不同大小的数据包。接收器捕获这些数据包并在程序终止时计算 PRR。

发射器和接收器之间的距离约为 6-7 英尺

对于这种 TCP/IP 设置,0.87 的数据包接收率是正常的还是偏低?

发射机:

 void sendMedicalStream(void) {

  timer_count ++;

  if(timer_count % 5 ==0) {        

  memcpy(pu8 ,(struct pulse_oxim_packet*)& oxim_packet , sizeof(struct 
              pulse_oxim_packet));
   x=send(s,pu8,sizeof(u8aSendBuffer),0); 
  }

  if(timer_count % 50 == 0) {    
   memcpy(pu8 ,(struct ecg_data*)& wifi_ecg_data , sizeof(struct ecg_data));
   x=send(s,pu8,sizeof(u8aSendBuffer),0);
  }

   if(timer_count % 10 == 0) {  
   memcpy(pu8 ,(struct resp_monitor_packet*)& rsp_mon_packet , sizeof(struct   
                                                              resp_monitor_packet));
   x=send(s,pu8,sizeof(u8aSendBuffer),0);
    }

    if(timer_count % 120 == 0) {  
    memcpy(pu8 ,(struct self_check_glucose_monitor_packet*)& gm_packet , sizeof(struct 
                           self_check_glucose_monitor_packet));
    x=send(s,pu8,sizeof(u8aSendBuffer),0);
   }

     if(timer_count % 30 == 0) {  
    memcpy(pu8 ,(struct self_check_weight_monitor*)& wm_packet , sizeof(struct 
                                                   self_check_weight_monitor));
     x=send(s,pu8,sizeof(u8aSendBuffer),0);
    }

  if(timer_count % 25 == 0) {  
   memcpy(pu8 ,(struct asthma_monitor*)& as_mon_packet , sizeof(struct asthma_monitor));
   x=send(s,pu8,sizeof(u8aSendBuffer),0);
   }

  if(timer_count % 35 == 0) {  
    memcpy(pu8 ,(struct  sc_blood_press_mon_packet*)& bp_mon_packet , sizeof(struct 
                      sc_blood_press_mon_packet));
    x=send(s,pu8,sizeof(u8aSendBuffer),0);
  }

 if(timer_count % 45 == 0) {  
  memcpy(pu8 ,(struct  insulin_pump_packet*)& ins_pump_packet , sizeof(struct 
                         insulin_pump_packet));
   x=send(s,pu8,sizeof(u8aSendBuffer),0);
  }


  if(timer_count % 15 == 0) { 
   memcpy(pu8 ,(struct  fetal_heart_monitor *)& fhm_packet , sizeof(struct 
                            fetal_heart_monitor));
    x=send(s,pu8,sizeof(u8aSendBuffer),0);
  }
   if(timer_count % 180 == 0) {  
   memcpy(pu8 ,(struct dialysis_machine *)& dial_mach_packet , sizeof(struct 
                      dialysis_machine));
   x=send(s,pu8,sizeof(u8aSendBuffer),0);

  }

  if(timer_count == 10000)
   timer_count = 0;
  }

 int main(int argc,char **argv)
  {

struct sockaddr_in sin;

 /* Packet Title DEtails */
    strcpy(fhm_packet.title,"Fetal-Heart-Rate-Monitor");
    strcpy(bp_mon_packet.title,"Blood-Pressure-Monitor");
    strcpy(ins_pump_packet.title,"Insulin-Pump-Monitor");
    strcpy(wm_packet.title,"Weight-Monitor");
    strcpy(as_mon_packet.title,"Asthma-Monitor");
    strcpy(gm_packet.title,"Glucose-Level-Monitor");
    strcpy(rsp_mon_packet.title,"Infant-Respiratory-Monitor");
    strcpy(dial_mach_packet.title,"Dialysis-Machine");


    /* Socket Details */   
    len=sizeof(struct sockaddr);

    if(argc==2){
    host =argv[1];
    }

   /* translates the host name into peer's IP address */

   hp=gethostbyname(host);
    if(!hp){
    fprintf(stderr,"duplex-talk : uknown host : %s\n",host);
    exit(1);
    }

   /* build address data structures */

    bzero((char *)&sin, sizeof(sin));
    sin.sin_family = AF_INET;
    bcopy(hp->h_addr,(char *)(&sin.sin_addr),hp->h_length);
    sin.sin_port = htons(SERVER_PORT);

     /* active open */
    if((s = socket(PF_INET,SOCK_STREAM,0))<0) {
    perror("duplex-talk : socket");
    exit(1);
     }

    if(connect(s, (struct sockaddr *)&sin, sizeof(sin)) <0) {
    perror("duplex-talk : connect");
    exit(1);
   }


  /* Timer Details */

  struct itimerval it_val;  /* for setting itimer */

   if (signal(SIGALRM, (void (*)(int)) sendMedicalStream) == SIG_ERR) {
   perror("Unable to catch SIGALRM");
    exit(1);
   }


   it_val.it_value.tv_sec =     MIN_INTERVAL/1000;
   it_val.it_value.tv_usec =    (MIN_INTERVAL*1000) % 1000000;   
   it_val.it_interval = it_val.it_value;

   if (setitimer(ITIMER_REAL, &it_val, NULL) == -1) {
   perror("error calling ECG setitimer()");
   exit(1);
   }


 /* main loop : get and send lines of text */
  int i=0,j=0;  
 while(1);

 }

接收者 :

 int main(int argc,char *argv)
  {
   char * pu8 = u8aSendBuffer;
   signal(SIGINT,INThandler);
struct sockaddr_in sin;
struct sockaddr addr;
socklen_t fromlen;
char buf[MAX_LINE];


len=sizeof(struct sockaddr);

/* build address data structues */

bzero((char *)&sin, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(SERVER_PORT);

/* setup passive open*/

if((s=socket(PF_INET,SOCK_STREAM,0))<0) { 
      perror("duplex-talk:socket");
       exit(1);
   }

   if((bind(s,(struct sockaddr *)&sin, sizeof(sin))) < 0){

    perror("duplex-talk: bind");
    exit(1);
   }

    // listen
  listen(s,MAX_PENDING);

    if((new_s = accept(s,(struct sockaddr *)&sin, &len)) < 0) {
    perror("duplex-talk : accept");
     exit(1);
  }

  while(1)
  {


    recv(new_s,pu8,sizeof(u8aSendBuffer),0);

    p_ptr = (struct pulse_oxim_packet *)pu8;
    ecg_ptr = (struct ecg_data *)pu8;
    resp_mon_ptr = (struct resp_monitor_packet *)pu8;
    gmon_ptr = (struct self_check_glucose_monitor_packet *)pu8;
    wmon_ptr = (struct self_check_weight_monitor *)pu8;
    asmon_ptr = (struct asthma_monitor *)pu8;
    bp_mon_ptr = (struct sc_blood_press_mon_packet *)pu8;
    ins_pump_packet = (struct insulin_pump_packet *)pu8;
    ft_mon_ptr = (struct fetal_heart_monitor *) pu8; 
    dial_mach_ptr = (struct dialysis_machine *) pu8;     



  if( p_ptr != NULL && strcmp(p_ptr->title,"Pulse-Oximeter-Data") == 0) 
    recv_count++;
  if( ecg_ptr != NULL &&  strcmp( ecg_ptr->title,"ECG-Monitor-Data") == 0 )
    recv_count++;
  if( gmon_ptr != NULL &&  strcmp( gmon_ptr->title,"Glucose-Level-Monitor") == 0 )
     recv_count++;
  if( asmon_ptr != NULL &&  strcmp( asmon_ptr->title,"Asthma-Monitor") == 0 )
     recv_count++;
  if(wmon_ptr != NULL &&  strcmp( wmon_ptr->title,"Weight-Monitor") == 0 )
     recv_count++;
    if( ins_pump_packet != NULL && strcmp( ins_pump_packet->title,"Insulin-Pump-Monitor") 
                             == 0)
     recv_count++;
  if( bp_mon_ptr != NULL &&  strcmp(bp_mon_ptr->title,"Blood-Pressure-Monitor") == 0 )
     recv_count++;
  if( ft_mon_ptr != NULL &&  strcmp( ft_mon_ptr->title,"Fetal-Heart-Rate-Monitor") == 0 )
     recv_count++;
   if( dial_mach_ptr != NULL &&  strcmp( dial_mach_ptr->title,"Dialysis-Machine") == 0 )
     recv_count++;
   }

   return 0;
  }
4

1 回答 1

1

我不是网络专家,但如果您的发射器持续传输数据包,则很可能会比通常情况下对 ACK 数据包产生更多的干扰。

我的猜测是,如果您稍微修改它以使其不会使连接饱和,您会发现您获得更高的数据包接收率。

编辑:看过你的代码后,我相信一个可能的问题是,即使你已经创建了一个基于流的套接字,你并没有它当作一个套接字——你假设每次recv调用都会得到一个数据包:

recv(new_s,pu8,sizeof(u8aSendBuffer),0);

您应该使用 from 的返回值来查看实际收到recv了多少字节。

由于接收窗口非常小(我不知道是什么),在这种情况下你可能会忽略它,sizeof(u8aSendBuffer)但通常你应该像你一样将流视为数据包序列:您应该将其视为数据流,您可能会或可能不会收到您要求的尽可能多的数据。

于 2012-07-22T20:06:01.693 回答