https://github.com/tariqjamel/inter-process-communication
This project demonstrates IPC using System V message queues in C. It includes a server and two clients that communicate through message queues. The server receives and forwards messages between clients, enabling continuous communication.
https://github.com/tariqjamel/inter-process-communication
c interprocess-communication operating systemcall thread
Last synced: 5 months ago
JSON representation
This project demonstrates IPC using System V message queues in C. It includes a server and two clients that communicate through message queues. The server receives and forwards messages between clients, enabling continuous communication.
- Host: GitHub
- URL: https://github.com/tariqjamel/inter-process-communication
- Owner: tariqjamel
- Created: 2024-06-28T07:40:02.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-28T11:26:49.000Z (over 1 year ago)
- Last Synced: 2025-05-15T04:35:36.900Z (10 months ago)
- Topics: c, interprocess-communication, operating, systemcall, thread
- Language: C
- Homepage:
- Size: 262 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Inter-Process Communication (IPC)
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.
## Project Structure
- `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.
## Screenshots

## Compilation and Execution
### Compile the Programs
- gcc -o server server.c -lpthread
- gcc -o client1 client1.c -lpthread
- gcc -o client2 client2.c -lpthread
## How It Works
1. The server creates a message queue and waits for messages from the clients.
2. Each client sends messages to the server.
3. The server prints the received messages and forwards them to the other client.
4. Clients have separate threads to receive and print messages forwarded by the server.
## Code Details
### `server.c`
- 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`.
### `client1.c`
- 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.
### `client2.c`
- 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.
## Requirements
- A POSIX-compliant operating system (e.g., Linux).
- GCC compiler.
- Basic understanding of inter-process communication in C.
## Contributing
Contributions are welcome! If you have any suggestions, bug fixes, or feature implementations, please submit a pull request.