Part B-2
P6client.c
#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>
#define FIFO1 "fifo1"
#define FIFO2 "fifo2"
int main()
{
char p[100], f[100], c[300];
int num, num2, f1,fd,fd2;
mknod(FIFO1, S_IFIFO | 0666, 0);
mknod(FIFO2, S_IFIFO|0666, 0);
printf("\n\n waiting for server......\n\n\n");
fd = open ( FIFO1, O_WRONLY);
printf("\n\n\n server online !! Enter the path .....\n\n");
while (scanf ("%s",
&p) && (!feof(stdin)))
{ if( ( num=write(fd,p,strlen(p))) == -1)
perror("\n\nwrite
Error");
else
{ printf("\n\nwaiting for reply....\n\n");
fd2 = open(FIFO2, O_RDONLY);
if((num2= read(fd2, c,300)) ==-1)
perror("\n\n transfer
error....\n\n");
else
{ printf("\n\n File
received.Showin contents..\n");
if (fputs(c,stdout)==EOF)
perror("print Error
....\n\n");
exit(1);
}
}
}
}
P6server.c
#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>
#define FIFO1 "fifo1"
#define FIFO2 "fifo2"
int main()
{
char p[100], f[100], c[100];
int num, num2, f1,fd,fd2;
mknod (FIFO1, S_IFIFO | 0666, 0);
mknod (FIFO2, S_IFIFO | 0666, 0);
printf("\n\n SERVER ONLINE........\n\n\n");
fd = open(FIFO1, O_RDONLY);
printf("\n\n\n wait for request.......\n\n");
while(1)
{ if ((num=read(fd,p,100)) == -1)
perror("\n\n READ
error\n\n");
else
{ p[num] = '\0';
if((f1 = open(p, O_RDONLY))
< 0)
{ printf("\n\nServer
: %s not found", p);
exit(1);}
else
{ printf ("\nserver : %s
is found.transferring", p);
stdin = fdopen(f1,
"r");
if(fgets(c, 1024,stdin)
!=NULL)
{fd2 = open(FIFO2,
O_WRONLY);
if(num2=write(fd2,c,strlen(c)) ==-1)
perror("\n\ntransfer error.....\n\n");
else
printf("\nserver
transfer complete!!\n");
}
elseperror ("\n\nRead Error!! \n\n");
exit(1);
}
}
}
}
Comments
Post a Comment