This project demonstrates inter-process communication using System V message queues in C. It consists of a server and two clients (Client 1 and Client 2). The server waits for messages from both clients, prints them to the console, and then forwards the messages to the other client.
server.c
: Implements the server that receives messages from clients and forwards them.client1.c
: Implements Client 1 which sends messages to the server and receives messages from Client 2.client2.c
: Implements Client 2 which sends messages to the server and receives messages from Client 1.
- gcc -o server server.c -lpthread
- gcc -o client1 client1.c -lpthread
- gcc -o client2 client2.c -lpthread
- The server creates a message queue and waits for messages from the clients.
- Each client sends messages to the server.
- The server prints the received messages and forwards them to the other client.
- Clients have separate threads to receive and print messages forwarded by the server.
- Initializes a message queue using
msgget
. - Waits for messages from Client 1 (type 1) and Client 2 (type 3) using
msgrcv
. - Prints received messages and changes the message type (2 for Client 1 and 4 for Client 2).
- Forwards the messages to the respective clients using
msgsnd
.
- Connects to the message queue created by the server.
- Uses a separate thread to receive messages of type 2.
- Reads user input and sends it to the server with message type 1.
- Connects to the message queue created by the server.
- Uses a separate thread to receive messages of type 4.
- Reads user input and sends it to the server with message type 3.
- A POSIX-compliant operating system (e.g., Linux).
- GCC compiler.
- Basic understanding of inter-process communication in C.
Contributions are welcome! If you have any suggestions, bug fixes, or feature implementations, please submit a pull request.