EmbLogic's Blog

Client Server Communication using Linux and IPC

Project : Client Server Communication using Linux and IPC

Overview :

Hi all This project is regarding Inter-process Communication techniques in this project ,

Before explaining IPC i must let you know why we need these type of techniques .

In user space each process have its own separated address space. Suppose if any process wants to send any information or data to the another process which is running in different address space then we need these IPC techniques to communicate among the processes .

I have learned following techniques and some of them was synchronization techniques .

Like Pipes , FIFO (known as named pipes also), message queues , shared memory .

And synchronization techniques was Semaphore and a little bit about Mutex.

On the basis of these learned techniques I developed some projects , In my projects

there was a main process that is i called Server program.

To this main server there was three requesting clients and corresponding to these requesting clients there was three processing clients. Every requesting and every processing client was connected to the main server program .

All the requesting clients was sending the request and data to the main server program for the request were very simple like to add ,subtract ,multiply the numbers . This data was getting by the server program continuously an the corresponding request sent to the processing clients .

The processing was adding , subtracting, multiplying the data(numbers).

And the corresponding results was sent to the server .the result sent by the processing clients further sent to requesting clients.

For the communication between the process i used the techniques learned by me. As

i have explained in the beginning of my article , In my first project i used three pipes at requesting client and server side and same at server and processing clients side.

In my later projects i replaced pipes from FIFO and in the next projects FIFO was replaced by Message queues and shared memory .But when i was writing the code i faced some concurrency (synchronization) issues .To resolve these issues i used semaphores in all my projects .

Lets go inside my projects

Project Internals :

First off all i created six pipe in server program for each child process these child process was created using a process duplication function that is fork() and now i was having six child process each having its own PID(process id ).Now my next task was to replace these child process from my own written requesting and processing clients .

That i have done use process replacement system call execv() . In this call i passed read and write file descriptor obtained from pipe(fd) system call as an argument to the excev() call .

I done the same for all clients by doing this my all requesting and processing clients was running independently .with the same PID of the child .

Now my next task was to start communication between the processes .

All the requesting clients were sending the data to the server using write file descriptor that was sent by the server ,to send data i used write() system call.

Corresponding to this there was in the server a read() was waiting for the data.

There was a condition of block on read ,until and unless writer writes the data on pipe.

In the data writer was sending two operand and one operator .Server was checking the operand and in its data base maintained by the server and invoking the corresponding processing client .After invoking processing client the server was sending the data using write() system call .

And was waiting for the result using read() system call .Here was also block on read condition.

To prevent from Zombies and oprphan process and used a function wait(pid) .So the main server does not terminate until its child does not terminate properly.

Issues faced :

I faced many issues some of them are listed below -

  • I faced synchronization problem ,actually when ever i was sending the data from requesting clients it was reading back its first byte as the result , without waiting for the result .

    So in the server program i was getting only 2 byte of data as 1 byte we have lost .

    So to block the requesting client until server read the requested data i used semaphores.

    A famous synchronization technique.

Thank You

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>