我使用两台笔记本电脑进行实验设置,一台作为发射器,另一台作为接收器。发送器根据已配置的不同定时器的时间段连续发送不同大小的数据包。接收器捕获这些数据包并在程序终止时计算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;
}
答案 0 :(得分:1)
我不是网络专家,但如果您的发送器连续传输数据包,则很可能会引入比通常情况下更多的ACK数据包干扰。
我的猜测是,如果你稍微修改它以使它不会使连接饱和,你会发现你获得了更高的数据包接收率。
编辑:看过你的代码之后,我相信一个可能的问题是即使你已经创建一个基于流的套接字,你也不会将视为一个 - 你假设每次recv
电话会收到一个数据包:
recv(new_s,pu8,sizeof(u8aSendBuffer),0);
您应该使用recv
的返回值来查看实际已收到的字节数。
可能你可以在这种情况下忽略它,因为它有一个非常小的接收窗口(我不知道sizeof(u8aSendBuffer)
是什么),但一般来说你应该不将流视为一系列数据包,就像你一样:你应该将它视为一个数据流,你可能会收到或不会收到你要求的数据。