Skip to content
Snippets Groups Projects
Commit 4a8295ec authored by Nico Ramos's avatar Nico Ramos
Browse files

aaaaaaa

parent a32d8bab
No related branches found
No related tags found
1 merge request!11Resolve "junção de arquivos e mensagens"
......@@ -208,18 +208,16 @@ string client::calc_file_size(string fileName) {
vector<char> client::read_file(string fileName) {
fstream file;
file.open(fileName, ios::in);
file.open(fileName, ios::binary);
string teste;
vector<char> fileData;
char c;
while ((file.get(c), file.eof() == false)) {
fileData.push_back(c);
teste.push_back(c);
}
file.close();
cout << "vetor criado: " << teste << "\n";
return fileData;
}
......@@ -259,7 +257,13 @@ void client::send_file() {
cout << "Enviando arquivo\n";
vector<char> file = read_file(fileName);
if (file.empty() || !send_message(file, DADOS))
if ( file.empty() )
{
cout << "Falha ao abrir o arquivo para leitura. Abortado\n";
return;
}
if (!send_message(file, DADOS))
{
cout << "Limite de timout, arquivo nao foi enviado\n";
return;
......
......@@ -115,7 +115,7 @@ void server::receive_text(frame *f) {
int lastSeq = f->get_seq();
do {
if (!receive_valid_frame(&f)) { continue; }
if (!receive_valid_frame(&f)) { return; }
if (f->get_tipo() != TEXTO) { continue; }
if (f->get_seq() == lastSeq) { continue; }
......@@ -183,7 +183,7 @@ string server::receive_file_name() {
// Aguarda receber um frame do tipo midia com o nome do arquivo
do {
if (!receive_valid_frame(&fReceive)) { continue; }
if (!receive_valid_frame(&fReceive)) { return string {}; }
if (fReceive->get_tipo() != MIDIA) { continue; }
if (strncmp(fReceive->get_dado(), "NAME", 4)) { continue; }
......@@ -200,24 +200,34 @@ string server::receive_file_name() {
return string(fReceive->get_dado()+4);
}
// void server::receive_file_data(){
// vector<frame *> framesMidia;
// receive
int server::receive_file_data(string fileName) {
// };
// Abre o arquivo para escrita
ofstream file;
file.open(FILE_DESTINATION+"/"+fileName);
if (!file.is_open()) {
cout << "Falha ao criar o arquivo. Abortado\n";
return 0;
}
cout << "Arquivo criado com sucesso\n";
int server::receive_file_data(string fileName) {
frame *fReceive;
int lastSeq = -1;
int retries = 0;
frame *f;
// Aguarda receber um frame do tipo midia com o nome do arquivo
do {
if (!receive_valid_frame(&fReceive)) { continue; }
if (fReceive->get_tipo() != MIDIA) { continue; }
if (strncmp(fReceive->get_dado(), "NAME", 4)) { continue; }
} while( fReceive->get_tipo() != FIMT);
};
if (!receive_valid_frame(&f)) { return 0; }
if (f->get_tipo() != DADOS) { continue; }
if (f->get_seq() == lastSeq) { continue; }
lastSeq = f->get_seq();
file.write(f->get_dado(), f->get_tam());
} while (f->get_tipo() != FIMT);
cout << "Arquivo recebido com sucesso\n";
file.close();
return 1;
}
void server::receive_midia(frame *f) {
if (!create_received_dir()) { return; }
......@@ -227,7 +237,7 @@ void server::receive_midia(frame *f) {
if (fileName.size() == 0) { return; }
if (!receive_file_data(fileName)) { return; }
receive_file_data(fileName);
}
// Recebe um frame do cliente
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment