E
ericunfuk
I have posted a few other posts before this one today, I still can't
solve my problem, I think I need to elaborate my problem now.
I'm trying to send a file using UDP, below is a segment of my sender
app, the sender and the receiver are both on the same machine and I
have an Internet emulation gateway running on the same machine as
well.
What I'm confused about is I can't detect when the end of the file I'm
sending has been reached, my program seems to be running forever.
Bascially the window[] in my code fragment is generated by the
receiver app, it contains the sequence numbers of packets, a zero
value in window indicates that packet has been successfully received
by the receiver, non-zero values indicate the sequence numbers of
packets that were not received by the receiver, thus need to be resent
by the sender app.
So I need to use fseek() to seek through the file, using the values in
window[] as offsets, but my receiver is stupid it doesn't know the
biggest possible sequence number, it just asks for greater sequence
numbers if previous smaller sequence numbers have all been received,
so in window[] it might contain some sequence number that when used as
offset to fseek(), fseek() will seek beyond the actual end of the
stream representing the file(I maybe wrong here becasue of my poor
understanding of stream, file etc..), I tried to find the size of the
file first then try to stop invoke fseek() , if offset times packet
size is greater than my file_size, but that didn't stop the pain, it
still runs forever.
Thank you all for any help you could provide.
Eric
..........
...........
while(last_packet_acked == 0){
for(i=0;i<win_size;i++){
if(window==0){continue;}
offset = window-1;
printf("size:%u\n",offset*5);
if(offset*5 <= file_size){fseek(file,offset,SEEK_SET);}
if((bytes_read=fread(packet.data,1,sizeof(packet.data),file))!=0)
{
packet.client_seq_no = htonl(window);
n = sendto(sock,&packet,sizeof(struct dgram),0,(struct sockaddr
*)&gateway,sizeof(struct sockaddr_in));
if(n<0) error("Error sendto");
printf("SENT PACKET:%u\n",window);
}else{
packet.client_seq_no = htonl(window);
packet.flag = htons(FIN);
n = sendto(sock,&packet,sizeof(struct dgram),0,(struct
sockaddr *)&gateway,sizeof(struct sockaddr_in));
if(n<0) error("Error sendto");
printf("SENT PACKET:%u\n",window);
break;
}
}
...............
...............
solve my problem, I think I need to elaborate my problem now.
I'm trying to send a file using UDP, below is a segment of my sender
app, the sender and the receiver are both on the same machine and I
have an Internet emulation gateway running on the same machine as
well.
What I'm confused about is I can't detect when the end of the file I'm
sending has been reached, my program seems to be running forever.
Bascially the window[] in my code fragment is generated by the
receiver app, it contains the sequence numbers of packets, a zero
value in window indicates that packet has been successfully received
by the receiver, non-zero values indicate the sequence numbers of
packets that were not received by the receiver, thus need to be resent
by the sender app.
So I need to use fseek() to seek through the file, using the values in
window[] as offsets, but my receiver is stupid it doesn't know the
biggest possible sequence number, it just asks for greater sequence
numbers if previous smaller sequence numbers have all been received,
so in window[] it might contain some sequence number that when used as
offset to fseek(), fseek() will seek beyond the actual end of the
stream representing the file(I maybe wrong here becasue of my poor
understanding of stream, file etc..), I tried to find the size of the
file first then try to stop invoke fseek() , if offset times packet
size is greater than my file_size, but that didn't stop the pain, it
still runs forever.
Thank you all for any help you could provide.
Eric
..........
...........
while(last_packet_acked == 0){
for(i=0;i<win_size;i++){
if(window==0){continue;}
offset = window-1;
printf("size:%u\n",offset*5);
if(offset*5 <= file_size){fseek(file,offset,SEEK_SET);}
if((bytes_read=fread(packet.data,1,sizeof(packet.data),file))!=0)
{
packet.client_seq_no = htonl(window);
n = sendto(sock,&packet,sizeof(struct dgram),0,(struct sockaddr
*)&gateway,sizeof(struct sockaddr_in));
if(n<0) error("Error sendto");
printf("SENT PACKET:%u\n",window);
}else{
packet.client_seq_no = htonl(window);
packet.flag = htons(FIN);
n = sendto(sock,&packet,sizeof(struct dgram),0,(struct
sockaddr *)&gateway,sizeof(struct sockaddr_in));
if(n<0) error("Error sendto");
printf("SENT PACKET:%u\n",window);
break;
}
}
...............
...............