Vous êtes sur la page 1sur 6

AIM:FULL DUPLEX COMMUNICATION USING NAMED PIPE

ROLL NO- s104179

Server-side coding

ser.c
#include<stdio.h>

#include<fcntl.h>

#include<string.h>

#define NP1 “N1”

#define NP2 “N2”

int main()

int ser,cli;

char data[50];

mkfifo("N1",0666);

mkfifo("N2",0666);

ser=open("N1",O_WRONLY);

cli=open("N2",O_RDONLY);
while(1)

printf("\n Server - ");

gets(data);

if(strcmp(data,"out")==0)

break;

write(ser,data,sizeof(data));

if(read(cli,data,50))

printf("\nClient - %s",data);

if(strcmp(data,"out")==0)

break;

OUTPUT:
sanket@linuxmint ~ $ cc ser.c
/tmp/ccnDWhHt.o: In function `main':

ser.c:(.text+0x85): warning: the `gets' function is dangerous and should not be used.

sanket@linuxmint ~ $ ./a.out

Server - hi

are you there

Client - fine

Server - ^[[Aout

Server - sanket@linuxmint ~ $

sanket@linuxmint ~ $ cc ser.c

Client-side coding

cli.c
#include<stdio.h>

#include<fcntl.h>

#include<string.h>

#define NP1 “N1”


#define NP2 “N2”

int main()

int s,c;

char msg[50];

s=open("N1",O_RDONLY);

c=open("N2",O_WRONLY);

while(1)

if(read(s,msg,50))

printf("\nClient - %s",msg);

if(strcmp(msg,"out")==0)

break;
printf("\n Server - ");

gets(msg);

if(strcmp(msg,"out")==0)

break;

write(c,msg,sizeof(msg));

//if(read(cl1,data,50);

printf("\nFrom Server - %s",msg);

if(strcmp(msg,"out")==0)

break;

OUTPUT:
sanket@linuxmint ~ $ cc cli.c

/tmp/ccluEw98.o: In function `main':


cli.c:(.text+0xae): warning: the `gets' function is dangerous and should not be used.

sanket@linuxmint ~ $ ./a.out

Client - hi

Server - fine

From Server - fineClient - are you there

Server - out

sanket@linuxmint ~ $ cc cli.c

Vous aimerez peut-être aussi