Skip to content

Commit 94e4415

Browse files
committed
Almost worked
1 parent bb936dc commit 94e4415

File tree

5 files changed

+3
-1
lines changed

5 files changed

+3
-1
lines changed

go-back-n/gbn.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void handle_alarm(int sig){
2323
printf("RETRY: %d\n",state.retry);
2424
if(state.retry<=5){
2525
state.seq_curr=state.seq_base;
26+
state.seqnum=state.seq_base+1;
2627
state.retry++;
2728
state.win_size=1;
2829
}
@@ -88,7 +89,7 @@ ssize_t gbn_send(int sockfd, const void *buf, size_t len, int flags){
8889
/*Reached end of window, wait for the correct ACK*/
8990
while(state.seq_curr-1==state.seq_max){
9091
if(state.retry<=5){
91-
if (state.seq_curr>packet_num) return (0);
92+
if (state.seq_base>packet_num) return (0);
9293
gbnhdr *packet = malloc(sizeof(*packet));
9394
status = recvfrom(sockfd, packet, sizeof(*packet), 0, state.address, &state.socklen);
9495
if(status!=-1 ){
@@ -136,6 +137,7 @@ ssize_t gbn_recv(int sockfd, void *buf, size_t len, int flags){
136137
printf("INFO: DATA received successfully.\n");
137138
/* Receiver responds with DATAACK */
138139
ack_packet->type=DATAACK;
140+
if(state.seqnum==N+1)state.seqnum=1;
139141
printf("INFO: Packet seqnum : %d State seqnum: %d\n",packet->seqnum,state.seqnum);
140142
if(state.seqnum == packet->seqnum){
141143
printf("INFO: Received DATA packet is in sequence.\n");

go-back-n/gbn.o

136 Bytes
Binary file not shown.

go-back-n/r.test

1.92 MB
Binary file not shown.

go-back-n/receiver

0 Bytes
Binary file not shown.

go-back-n/sender

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)