0% found this document useful (0 votes)
42 views3 pages

Naman Khybri

The document describes server-side and client-side code for inter-process communication using a FIFO pipe. The server-side code defines a function to read from the pipe and decode encoded text. It then creates the pipe and calls the read function. The client-side code takes user input, encodes any special characters, writes the encoded text to the pipe, and terminates the connection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Naman Khybri

The document describes server-side and client-side code for inter-process communication using a FIFO pipe. The server-side code defines a function to read from the pipe and decode encoded text. It then creates the pipe and calls the read function. The client-side code takes user input, encodes any special characters, writes the encoded text to the pipe, and terminates the connection.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT - IV

SERVER-SIDE CODE :-

#include <stdio.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h> // read(), write(), close()
//fuction for reading from user
int r_read(int res){
char buf[100],ans[100];
int ctr=0;
res=open("myfifo",O_RDONLY);
read(res,buf,100);//reading data from pipe
for(int i=1;i<sizeof(buf);i++)
{
if(buf[i]=='$')
{
ans[ctr]=buf[i+1];
i++;
} //Decoding data from pipe
else{
ans[ctr]=buf[i];
}
if(buf[i]=='#'&&buf[i+1]=='\0')
{
ans[ctr]=buf[i+1];//for erasing end #
}
ctr++;
}

//printf("\n raw data :%s\n",buf);//printing raw data


printf("\n data is : %s\n",ans);//displaying data
}
//end of function r_read
int main()
{
int res ,len;
res=mkfifo("myfifo",0766);//creating myfifo
if(res==0){
printf("\nfifo created....");
}
res=r_read(res);//fuction call for reading from user.
return 0;
}

ASSIGNMENT - IV 1
CLIENT-SIDE CODE :-

#include <stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include <string.h>
#include <unistd.h>// read(), write(), close()
#include <stdlib.h>
//staring of main
int main()
{
int res,code;//response pointer
char buf[100];
char newmsg[100];//newmsg buffer
int ctr=1;//counter Setting
char newbuf[2]="#";
printf("enter any word: ");
scanf("%s",buf);//Taking Input for user
newmsg[0]='#';
for(int i=0;i<sizeof(buf);i++){
if(buf[i]=='#'||buf[i]=='$'){
newmsg[ctr]='$';
newmsg[ctr+1]=buf[i];
ctr++;
ctr++;
}
else{
newmsg[ctr]=buf[i];
ctr++;
}
}
strcat(newmsg,newbuf);
printf("data is: %s\n",newmsg);
res=open("myfifo",O_WRONLY);
write(res,newmsg,100);
printf("\nconnection ends...\n");//connection terminated
return 0;

OUTPUT :-

ASSIGNMENT - IV 2
SERVER :

CLIENT :

ASSIGNMENT - IV 3

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy