This is a very basic implementation of two 'users' communicating with eachother on a local machine via IPC (Inter-process communication).
In this projects named pipes are used for IPC. Pipes are essentially channels that processes can use to communication with one another. One could think of pipes as a mail service. One processes sends mail to a mailbox and another process is able to read the mail from that mailbox. In simplest terms, this is what these two files (user1.c & user2.c) do. Two threads are created
send_thread
andreceive_thread
. These threads are then executed two calls ofpthread_create
. This allows for the two threads to run in parallel so that the program can receive data and send data concurrently.
This is made to run on Mac OS X and Linux
Compile using gcc
gcc -o user1 user1.c
gcc -o user2 user2.c
The best way to run these two executables is to
-
Open a terminal window and run the user1 exectuable
-
Open another terminal window and run the user2 executable
-
Now start chatting!
Check out this question on stack overflow.