diff --git a/headers/client.h b/headers/client.h index d4cc3c9856fcca52e2f3f7b72eb3eeac7a8758e6..8c1f21f56602248953dcb1548ecbf144e43fbd71 100644 --- a/headers/client.h +++ b/headers/client.h @@ -109,6 +109,11 @@ int client::start_transmission() { frame *ini = new frame(INIT, 0, vector<char>(1, 0)); frame *enviado = new frame(); enviado = send_frame_socket(ini); + int retries = 0; + while (!enviado && retries++ < NUM_RETRIES ){ + cout << BOLDRED << "\tFalha ao iniciar a transmissao, tentando novamente...\n"; // ->log + enviado = send_frame_socket(ini); + } if (!enviado) { // cout<< BOLDRED << "\tFalha ao iniciar a transmissao\n" << RESET; ->log return 0; @@ -142,9 +147,9 @@ int client::send_frames(vector<frame *> frames) { if (frames.empty()) { return 0; } - cout << "\tstart transmission\n"; + // cout << "\tstart transmission\n"; ->log if (!start_transmission()) { return 0; } - cout << "\t ->>> started transmission <<< -\n"; + // cout << "\t ->>> started transmission <<< -\n"; ->log // Adiciona o frame de fim de transmissao int next_seq = frames.back()->get_seq() + 1; @@ -162,12 +167,12 @@ int client::send_frames(vector<frame *> frames) { if (iniJanela + frameCounter == frames.size()) { break; } janela.push((iniJanela + frameCounter) % 16); - // cout << "\tEnviando frame\n"; ->log - // frames[iniJanela + frameCounter]->imprime(DEC); ->log - + cout << "\tEnviando frame: " << iniJanela + frameCounter << "\n"; + frames[iniJanela + frameCounter]->imprime(DEC); + if (socket->send_frame(frames[iniJanela + frameCounter]) == -1) { // cout << "Falha ao enviar o frame\n"; ->log - return 0; + continue; } // cout << "\tFrame enviado com sucesso\n"; ->log @@ -184,7 +189,10 @@ int client::send_frames(vector<frame *> frames) { res = receive_ack_nack(); } while (res == NULL && retries < NUM_RETRIES); - if (res == NULL && retries == NUM_RETRIES) { break; } + if (res == NULL && retries == NUM_RETRIES) { + // cout << "Numero maximo de tentativas excedido\n"; ->log + + break; } cout << "Resposta recebida\n"; cout << "Numero ack/nack: " << (int)res->get_dado()[0] << " ---- " @@ -213,8 +221,8 @@ int client::send_frames(vector<frame *> frames) { } // apaga a janela - while (!janela.empty()) - janela.pop(); + // while (!janela.empty()) + // janela.pop(); } cout << "\tTerminou de enviar todos os frames\n"; //->log diff --git a/headers/conexao.h b/headers/conexao.h index 378cd1261e8ae935149cf529d761ca5243e63be9..cf2fd6b1dcc6c6bc6d698a5967b5830a4e109fdd 100644 --- a/headers/conexao.h +++ b/headers/conexao.h @@ -23,7 +23,7 @@ #include "frame.h" using namespace std; -#define NUM_RETRIES 10 +#define NUM_RETRIES 20 #define TAM_JANELA 16 class conexao { @@ -50,7 +50,7 @@ private: void close_connection(); // fecha a conexao public: - int timeoutMillis = 200; // Tempo que fica tentando ler + int timeoutMillis = 400; // Tempo que fica tentando ler // ------ Construtor ------ // conexao(char *deviceIP); diff --git a/received/caco.png b/received/caco.png index 781ac8ded3238994b875d736a8be8364bbc73b8d..ed7f7696f6c27460bde083a10214df0d9473b37f 100644 Binary files a/received/caco.png and b/received/caco.png differ