Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
guim4dev committed Jul 29, 2021
1 parent e18fb12 commit d981996
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions TP1/sockets/consumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ using namespace std;

int main()
{
char buffer[20];
int server_fd, new_socket;
char buffer[30];
int server_fd, new_socket, valread;
struct sockaddr_in addr;
int addrlen = sizeof(addr);

Expand Down Expand Up @@ -58,14 +58,14 @@ int main()

while (true)
{
read(new_socket, buffer, sizeof(char) * 20);
valread = read(new_socket, buffer, sizeof(char) * 30);
int number = atoi(buffer);
if (number == 0)
break;
cout << "Received " << number << "..." << endl;
char response[20];
char response[30];
sprintf(response, "%i%s", number, (isPrime(number) ? " é primo." : " não é primo."));
send(new_socket, response, sizeof(char) * 20, 0);
send(new_socket, response, sizeof(char) * 30, 0);
}
// Fechando socket
close(server_fd);
Expand Down
6 changes: 3 additions & 3 deletions TP1/sockets/producer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ using namespace std;

int main()
{
int n;
int n, valread;
char host[16];
cout << "Insira o IPv4 do servidor:" << endl;
cin >> host;
cout << "Insira o número de números a serem enviados ao servidor:" << endl;
cout << "Insira quantos números serão enviados ao servidor:" << endl;
cin >> n;
int sock = 0;
struct sockaddr_in serv_addr;
Expand Down Expand Up @@ -59,7 +59,7 @@ int main()
cout << "Sending " << start_n << "..." << endl;
// Enviamos o buffer para o socket.
send(sock, buffer, sizeof(char) * 30, 0);
read(sock, buffer, 30);
valread = read(sock, buffer, 30);
cout << "[CONSUMER]: " << buffer << endl;
}
// Enviamos um 0 para o socket para indicar que os processos terminarão
Expand Down

0 comments on commit d981996

Please sign in to comment.