Displaying Source Code(s)
|
|
Client Server Program using FIFO
--------------------------------------------------------------------------------
Description : implement a single Client Server Program using
FIFO
client.c
--------
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<fcntl.h>
#define FIFO1 "temp1"
#define FIFO2 "temp2"
#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
void client(int r,int w)
{
int l,n;
char buf[80];
fgets(buf,80,stdin);
l=strlen(buf);
if(buf[l-1]=='
')
l--;
write(w,buf,l);
while((n=read(r,buf,80))>0)
write(STDOUT_FILENO,buf,n);
}
int main(int argc,char *argv[])
{
int readfd,writefd;
printf("Enter the File Name to Get:");
writefd=open(FIFO1,O_WRONLY,0);
readfd=open(FIFO2,O_RDONLY,0);
client(readfd,writefd);
close(readfd);
close(writefd);
}
server.c
--------
#include<stdio.h>
#include<unistd.h>
#include<errno.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
#define FIFO1 "temp1"
#define FIFO2 "temp2"
#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
void server(int r,int w)
{
int fd,n;
char buf[81];
if((n=read(r,buf,80))==0)
{
return;
}
buf[n]='
|
|
|