I have big problems because I donβt know how to do this. I need to create only 2 processes that can exchange information. This is the code:
this->sock_fd = this->w_socket(); this->w_bind(); this->w_listen(); std::cout << "[info] Server is running..." << std::endl; while(1) { struct sockaddr_in client_addr; int client_fd = this->w_accept(&client_addr); char client_ip[64]; int client_port = ntohs(client_addr.sin_port); inet_ntop(AF_INET, &client_addr.sin_addr, client_ip, sizeof(client_ip)); std::cout << "[info] Connection from (" << client_ip << ", " << client_port << ")" << std::endl; ... int pid = fork(); if (pid == 0) { close(this->sock_fd); this->manage(client_fd, client_ip, client_port); exit(0); } close(client_fd); }
Well. When the client successfully authenticates after the login manager, it can send data to the server. If the client is connected and the other is registered, the second should push the first client with the message "You were disconnected." How can I use fork and pipe for this? I tried to read something, but I'm a little confused.
Thanks.
user840718
source share