I have an experiment set-up using two laptop machines , one acting as a transmitter and another as receiver. The transmitter continuously transmits packets of different sizes , depending on the time period of different timers that have been configured. The receiver captures these packets and calculates the PRR upon termination of the program.
The transmitter and receiver are separated by a distance of about just 6-7 feet
Is a packet-reception ratio of 0.87 normal for this TCP/IP set-up or is it on the lower side?
Transmitter:
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);
}
Receiver :
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;
}
I’m not a networking expert, but if your transmitter is continuously transmitting packets, it’s quite possibly introducing far more interference with ACK packets than would normally be the case.
My guess is that if you modify it very slightly so that it doesn’t saturate the connection, you’ll find you get a much higher packet reception ratio.
EDIT: Having seen your code, I believe one possible problem is that even though you’ve created a stream-based socket, you’re not treating it as one – you’re assuming that you’ll get exactly one packet on each
recvcall:You should be using the return value from
recvto see how many bytes have actually been received.It’s possible that you’re semi-okay to ignore it in this case due to having a very small receiving window (I don’t know what
sizeof(u8aSendBuffer)is) but in generally you should not be treating the stream as a sequence of packets like you are: you should treat it as a stream of data, where you may or may not receive as much data as you ask for.