EmbLogic's Blog

Single Client Server Communication Using Socket In Using UNIX_AF With Use The Shell Script

RCS file: header.h,v
Working file: header.h
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;     selected revisions: 1
description:
In file all header files included this project related .
—————————-
revision 1.1
date: 2016/02/28 12:03:13;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: request.h,v
Working file: request.h
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;     selected revisions: 1
description:
In file structure declare named socket struct type in member varible are three all varibale char array type in
all array size 10-10 bytes.
—————————-
revision 1.1
date: 2016/02/28 12:29:12;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: request_client.c,v
Working file: request_client.c
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;     selected revisions: 1
description:
In file include a two user defined header file names are header.h and request.h them declare struct socket s3 variable^then call a strcpy function call this help the strings store the in member char array in variable then predefined socke^[[un.h header file in declare a structure named is struct sockaddr_un and in two member varible first is sun_family and second is sun_path and set the value in sun_family in give the domain name is AF_UNIX and then second in give the path is socket socket name is which derectory you want to created give the full path before a struct sockaddr_un type decalre a object
>> then give the assign path then call a socket and in give the argument first domain is AF_UNIX second is type is SOCK_STREAM then give the protocol is NULL because if u give the NULL then second agrument acording put the agrument is bydefsulkt bydefault and if second argument is SOCK_STREAM then put the protocol is TCP/IP then socket is created but unnamed then then call the connect and give the agrument socket fd and then type cast the sockaddr_un to sockaddr * because in seond argumet give the this data * then give then length socklen_t type then write the all structure data give the server in help help of the socket and if any condtions write return a 0 then report the write call .
----------------------------
revision 1.1
date: 2016/02/28 12:30:06;  author: root;  state: Exp;
Initial revision
=============================================================================

RCS file: server.c,v
Working file: server.c
head: 1.1
branch:
locks: strict
access list:
symbolic names:
keyword substitution: kv
total revisions: 1;     selected revisions: 1
description:
In file include a two user defined header file names are header.h and request.h them declare struct socket s3 variablethen call a strcpy function call this help the strings store the in member char array in variable then predefined socun.h header file in declare a structure named is struct sockaddr_un and in two member varible first is sun_family and second is sun_path and set the value in sun_family in give the domain name is AF_UNIX and then second in give the path is socket socket name is which derectory you want to created give the full path before a struct sockaddr_un type decalre a object
then give the assign path then call a socket and in give the argument first domain is AF_UNIX second is type is SOCK_STREAM then give the protocol is NULL because if u give the NULL then second agrument acording put the agrument is bydefsulkt bydefault and if second argument is SOCK_STREAM then put the protocol is TCP/IP then socket is created but unnamed then  call the bind in which give the argument in help of socket return fd on then bind is return succfully then call to return
then call to listen in agrumnet socket fd and how many client want a connect to server this listen is make a queue then
call to accept In give the arguement this make duplicate same unnamed socket and return the fd then
read the client data help of the socket and then check the how many succesfully bytes read if any condtion is falied rreturn is 0 then report the write call then if data successfully read then display this .
----------------------------
revision 1.1
date: 2016/02/28 12:04:47;  author: root;  state: Exp;
Initial revision
=============================================================================

SHELL SCRIPT

 

#! /bin/bash

delete()
{
rm -rf request_client
rm -rf server
rm -rf socket
}

edit()
{
read -p "do you want a edit further (y or n)" answer

if [ 'y' = $answer ]
then

for file in $(ls *.h,v)
do
co -l $file
done

for file in $(ls *.c,v)
do
co -l $file
done
delete
exit 0
fi
}

execute()
{
read -p “do you want a compile a project” answer

if [ 'y' = $answer ]
then
if ( gcc -o server  server.c)
then
echo “compile is successfull”
else
echo “compile is failed”
edit
fi

if ( gcc -o request_client request_client.c )
then
echo “compile is sucessfull”
else
echo “compile is failed”
edit
fi

else
edit
fi
read -p “do you want a execute this project” answer

if [ 'y' = $answer ]
then
./server & ./request_client

else
echo “execution is failed”
edit
fi

}

logfile()
{
read -p “do you want a run a logfile” answer

if [ 'y' = $answer ]
then
chmod +x rlog.sh
./rlog.sh
fi
}

for file in $(ls *.h)
do
ci $file
done

for file in $(ls *.c)
do
ci $file
done

for file in $(ls *.h,v)
do
co $file
done
for file in $(ls *.c,v)
do
co $file
done
execute
logfile
edit

logfile creted in shell script

#! /bin/bash

read -p “do you want a delete old file” answer

if [ 'y' = $answer ]
then
if [ -f logfile ]
then
rm -rf logfile
touch logfile
else
echo “logfile is not found”
fi
fi

read -p “do you want a update a logfile” answer

if [ 'y' = $answer ]
then
for file in $(ls *.h,v)
do
rlog $file >> logfile
done

for file in $(ls *.c,v)
do
rlog $file >> logfile
done
fi

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>