You are on page 1of 2

File: /home/prateek/Documents/nw-lab/practice/client.

c Page 1 of 1

#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
int main(int argc,char *argv[])
{
char p[100],c[3000];
int fd1,fd2;

mknod("fifo1",S_IFIFO|0666,0);
mknod("fifo2",S_IFIFO|0666,0);

printf("Client online\n");
printf("\n waiting for server...\n");

fd1=open("fifo1",O_RDWR);

printf("\n SERVER ONLINE !\n "


"CLIENT:Enter the path\n");
gets(p);
while(!feof(stdin))
{
write(fd1,p,strlen(p));
printf("Waiting for reply....\n");
fd2=open("fifo2",O_RDWR);
read(fd2,c,3000);
printf("File received! displaying the contents:\n");
fputs(c,stdout);
exit(1);
}
}
File: /home/prateek/Documents/nw-lab/practice/server.c Page 1 of 1

#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<string.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>

int main(int argc,char *argv[])


{
char p[100],c[300],ch;
int f1,fd1,fd2,i=0;

mknod("fifo1",S_IFIFO |0666,0);
mknod("fifo2",S_IFIFO |0666,0);

printf("\nSERVER ONLINE");
fd1=open("fifo1",O_RDONLY);
printf("client online\nwaiting for request\n\n");
while(1)
{
read(fd1,p,100);
f1=open(p,O_RDWR);
printf("\nserver:%s found\n"
"tranfering the contents",p);
stdin=fdopen(f1,"r");
while((ch=getc(stdin))!=EOF)
{
c[i++]=ch;
}
c[i]='\0';
printf("\nfile contents are:\n%s\n ",c);
fd2=open("fifo2",O_RDWR);
write(fd2,c,strlen(c));
printf("\nserver:transfer completed");
exit(1);
}
}

You might also like