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

Posted in Project 03: Client Server Communication using Linux and IPC | Leave a comment

ARTICLE

Client sever communication system using socket and multiple thread.

Description: It is a multiple client server project based on TCP socket and threads. Through this infinite number of client can communicate with each other and share information through the server on local network.

In this for i have created individual thread for each and every operation.

SERVER END : Through this all the user can interact with each other. Initially i have created a tcp socket which can be accessed through a combination of ip address and port number. Other calls used in this are BIND to associate your fd which was is your return value of socket call to a structure which contains information regarding your ip address and port number this is basically a naming convention. Then comes your listen call which gives you the number of client which can be held in your socket queue. You can select a port number which is not initialized for any other service. Then through accept call which accepts your client request and provide him a different fd so that it can accept request from new incoming client. Through this different client gets separate fd and can communicate with each other.

For each client there will be an individual thread as soon as a request from client is received, server will create a thread solely for that particular client.

Its has various functionality:

  1. when the first client sends its request to server if it is the only client the server will send him a message that you the only client. So wait till we have another client, then its all upto the client whether he wants to wait or he can quit the server.

  2. Lets say if another client arrive then the server will first send him the option of all the other clients who are still online. And then that client if wishes to connect any of present client it can send his id number to server and server will create a connection between them so that they can share information.

  3. In similar fashion it can connect as many client as asked.

CLIENT END: It include only two system call one is for creating your socket and other one is CONNECT to send a request to your server.

  1. First any of the client will send a request on successful completion of your your socket call in return it will receive a fd through which it can communicate with each other.

  2. As soon as 2 client comes into the picture the server will send him a request of the number of client which are online to select whom he/she wants to connect.

  3. Now our 2 client will have the fd of that client whom he wants to connect but the client on the other hand have no information of the 2nd client which ask the server to connect him to client 1. so before sending any sort of information first the second client will send his fd to 1st client through sever

  4. Now every client has two different thread depending on whether he/she wants to send a request or can directly receiver data if some other client already made a request to connect him to the former client. As we have seen in many social sites that we can receive msg from other client even if are not sending him some information.

This is all about what i have done to date and i am working on it for further amendments.

 Thanks & Regards

 

Posted in Uncategorized | Leave a comment

Character Device Driver

RCS file: header.h,v
Working file: header.h
head: 1.10
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 10;	selected revisions: 10
description:
This is the base module.
----------------------------
revision 1.10
date: 2013/10/31 07:36:18;  author: Emblogic;  state: Exp;  lines: +24 -0
defined macros DEV_SIZE, DATA_SIZE, QSET_SIZE, QUANTUM_SIZE and the corresponding variables.
defined the corresponding elements of the scull too.
----------------------------
revision 1.9
date: 2013/10/31 07:10:53;  author: Emblogic;  state: Exp;  lines: +1 -1
*** empty log message ***
----------------------------
revision 1.8
date: 2013/10/31 07:10:07;  author: Emblogic;  state: Exp;  lines: +1 -0
Included file slab.h
----------------------------
revision 1.7
date: 2013/10/31 07:04:42;  author: Emblogic;  state: Exp;  lines: +16 -2
added struct file_operations
includec cdev.h
defined struct ScullDev anf struct ScullQset
----------------------------
revision 1.6
date: 2013/10/31 06:39:50;  author: Emblogic;  state: Exp;  lines: +8 -1
defined macro MINORNO
defined variable minorno and assigned to MINORNO.
removen struct file_operations.
----------------------------
revision 1.5
date: 2013/10/31 06:25:17;  author: Emblogic;  state: Exp;  lines: +1 -0
included the file fs.h
----------------------------
revision 1.4
date: 2013/10/31 06:20:58;  author: Emblogic;  state: Exp;  lines: +12 -0
defined macros like MAJORNO, DEVNAME.
defined struct file_operations.
----------------------------
revision 1.3
date: 2013/10/29 07:34:51;  author: root;  state: Exp;  lines: +6 -0
Included moduleparam.h
declared the macro NOD and variable nod.
Assigned nod = NOD.
----------------------------
revision 1.2
date: 2013/10/28 07:33:00;  author: Emblogic;  state: Exp;  lines: +6 -0
Defined macros:
MODULE_DESCRIPTION() and MODULE_AUTHOR()
Also defined Macro DEBUG for printk's.
----------------------------
revision 1.1
date: 2013/10/28 07:29:36;  author: Emblogic;  state: Exp;
Initial revision
=============================================================================
Posted in Character Driver | Leave a comment

TCL FEDORA PROBLEM

Sir, how to run tcl scripts on fedora?

I have an  example:

# tclsh hello.tcl
can’t find package Tk
while executing

I tried to install Tk package, but its not working. Please help!!

Posted in Embedded Linux, Shell Scripts | Leave a comment

what is UNIX?

difference between linux and UNIX?

kindly explain from scratch

Posted in Uncategorized | Tagged , , , | Leave a comment

batch-39 project-1

kindly give me a suggestion to resolve question no-2 array assignment “in result i am getting a garbage value”

 

Posted in Data Structures with C | Tagged | Leave a comment

C program

# define min(a,b)  ((a)<(b))?(a):(b)

int main()

{ int i=0,a=0;

while(min(a++,9)<8)

i=i+1;

printf(“%d\n”,i);

return 0;

}

what will be output? how n why ?

Posted in Uncategorized | Tagged | Leave a comment

Log file for Character Device Driver

RCS file: header.h,v
Working file: header.h
head: 1.11
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 11;	selected revisions: 11
description:
This is the header for the base module.
----------------------------
revision 1.11
date: 2013/10/21 10:35:24;  author: root;  state: Exp;  lines: +4 -1
Mapped the system calls open() and release() to corresponding driver routines scull_open() and scull_release().
----------------------------
revision 1.10
date: 2013/10/21 10:31:46;  author: root;  state: Exp;  lines: +3 -0
Gave Prototypes for scull_open() and scull_release().
----------------------------
revision 1.9
date: 2013/10/21 09:28:04;  author: root;  state: Exp;  lines: +4 -2
included cdev.h
declared file_operations structure.
declared struct cdev inside struct ScullDev.
----------------------------
revision 1.8
date: 2013/10/21 09:01:57;  author: root;  state: Exp;  lines: +2 -2
*** empty log message ***
----------------------------
revision 1.7
date: 2013/10/21 08:55:36;  author: root;  state: Exp;  lines: +13 -0
Included slab.h
defined Struct ScullDev and Struct ScullQset.
----------------------------
revision 1.6
date: 2013/10/18 08:28:56;  author: root;  state: Exp;  lines: +8 -1
defined a macro MINORNO
defined variable dev.
commented strust file_operations.
----------------------------
revision 1.5
date: 2013/10/18 08:12:07;  author: root;  state: Exp;  lines: +13 -0
Included fs.h
defined macros like DEVNAME, MAJORNO.
defined struct file_operations.
----------------------------
revision 1.4
date: 2013/10/18 07:56:13;  author: root;  state: Exp;  lines: +1 -0
Included moduleparam.h
----------------------------
revision 1.3
date: 2013/10/18 07:55:28;  author: root;  state: Exp;  lines: +7 -0
Added Module_Descriotion() macro.
----------------------------
revision 1.2
date: 2013/10/17 08:08:56;  author: root;  state: Exp;  lines: +1 -0
Added MODULE_AUTHOR
----------------------------
revision 1.1
date: 2013/10/17 07:52:39;  author: root;  state: Exp;
Initial revision
=============================================================================
Posted in Character Driver | Leave a comment

batch 39 -doubt

is there any difference between float f==2.5f and float f=2.5 ????..

 

Posted in Uncategorized | Tagged | Leave a comment

batch 39 – project 01

plz guide me for solving Q2–>assignment-loops

Posted in Uncategorized | Tagged | Leave a comment

assignment

pls resolve a problem in question no 1 assignment 4 poject 1 in assinment of an aay.

How to represent a repeated no. one time only.

Posted in Uncategorized | Tagged | Leave a comment

problem in c assignment

pls resolve problem in question 6 of assignment 4 of project 1 . wat the input we should give and wat shoulb the output?

 

Posted in Uncategorized | Leave a comment

problem in assignment 4

mam,

pls resollve a problem in a question no. 5.

Posted in Uncategorized | Tagged | Leave a comment

Assignment status

ma’am,

I have completed assignment basic in c – 1 ,2 and conditional,currently i am doing loops.

Posted in Uncategorized | Leave a comment

Bizarre condition

whenever i open terminal, this ~~ automatically starts printing on my screen continuously…… it also create very much problem while typing….. and main thing is this is not a hardware problem of my laptop… because this problem was not there in windows 7 but this problem came in to notice after installing fedora 17. please suggest me what to do ???

Posted in Uncategorized | Tagged , , , | Leave a comment