Skip to content
Snippets Groups Projects
Commit bf7622a5 authored by Mertens De Andrade Guilherme's avatar Mertens De Andrade Guilherme
Browse files

client

parent cc1f87fc
No related branches found
No related tags found
No related merge requests found
#include <iostream>
#include <csignal>
#include <cstdlib>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
volatile bool running = true;
void handle_signal(int signal_number) {
std::cout << "Client received signal: " << signal_number << std::endl;
running = false;
}
int main() {
// Signal handling
struct sigaction sa;
sa.sa_handler = handle_signal;
sa.sa_flags = 0;
sigemptyset(&sa.sa_mask);
if (sigaction(SIGINT, &sa, nullptr) == -1 || sigaction(SIGTERM, &sa, nullptr) == -1) {
perror("Failed to set signal handler");
exit(EXIT_FAILURE);
}
const char* fifo_path = "my_fifo";
// Open FIFO for reading
int fd = open(fifo_path, O_RDONLY);
if (fd == -1) {
perror("Client failed to open FIFO for reading");
exit(EXIT_FAILURE);
}
int number;
while (running) {
// Read numbers from FIFO
if (read(fd, &number, sizeof(number)) > 0) {
std::cout << "Client received: " << number << std::endl;
} else {
perror("Failed to read from FIFO");
running = false;
}
sleep(1);
}
close(fd);
std::cout << "Client exiting..." << std::endl;
return 0;
}
/*
Client received: 49
Client received: 50
Client received: 51
Client received: 52
Client received: 53
Client received: 54
Client received: 55
Client received: 56
Client received: 57
*/
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment