Skip to content
Snippets Groups Projects
Commit f22af430 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Tryed to fix ack and nack in receive

parent 7a6d2d21
No related branches found
No related tags found
1 merge request!1Lento
...@@ -187,7 +187,7 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){ ...@@ -187,7 +187,7 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){
if(status == NOISE){ if(status == NOISE){
continue; continue;
} else if(status == type) { } else if(status == type) {
if(messages.back().sequence.to_ulong() != nextSequence){ if(!messages.empty() && (messages.back().sequence.to_ulong() != nextSequence)){
response.reset(); response.reset();
vector<BYTE> val(1,(BYTE)nextSequence); vector<BYTE> val(1,(BYTE)nextSequence);
response.setData(val, NACK); response.setData(val, NACK);
...@@ -197,6 +197,7 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){ ...@@ -197,6 +197,7 @@ int Protocol::receive(int sockt, int type, int window, bool dataEndable){
vector<BYTE> val(1,(BYTE)messages.back().sequence.to_ulong()); vector<BYTE> val(1,(BYTE)messages.back().sequence.to_ulong());
response.setData(val, ACK); response.setData(val, ACK);
nextSequence = (messages.back().sequence.to_ulong()+1)%(MAXSIZE+1); nextSequence = (messages.back().sequence.to_ulong()+1)%(MAXSIZE+1);
shouldSend = true;
} else { } else {
//TODO: treat something? //TODO: treat something?
} }
......
...@@ -17,6 +17,7 @@ int main(){ ...@@ -17,6 +17,7 @@ int main(){
} }
if(status == CD){ if(status == CD){
cout << "Recebeu CD\n"; cout << "Recebeu CD\n";
cout << "CD: " << receiveProtocol.getDataAsString() << endl;
cd(receiveProtocol.getDataAsString()); cd(receiveProtocol.getDataAsString());
}else if(status == LS){ }else if(status == LS){
cout << "protocol data: " << receiveProtocol.getDataAsString() << endl; cout << "protocol data: " << receiveProtocol.getDataAsString() << endl;
...@@ -25,6 +26,7 @@ int main(){ ...@@ -25,6 +26,7 @@ int main(){
cout << "LS: " << output << endl; cout << "LS: " << output << endl;
sendProtocol.setData(vector<BYTE>(output.begin(), output.end()), OUTPUT); sendProtocol.setData(vector<BYTE>(output.begin(), output.end()), OUTPUT);
sendProtocol.transmit(sockt, WAIT_STOP); sendProtocol.transmit(sockt, WAIT_STOP);
cout << "finished transmit" << endl;
}else if(status == PUT){ }else if(status == PUT){
//TODO //TODO
}else if(status == GET){ }else if(status == GET){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment