You are on page 1of 73

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week1:
Aim: To Implement the following of IPC a) Pipes b) FIFO

Description: -- A Pipe provides one way flow of data. -- Pipe is created by the pipe system call.

int pipe(int * filedes);

-- There are two file descriptors are returnedfiledes[0] which is open for reading and filedes[1] which is open for writing.

int pipe (int * filedes); int pipefd[2]; /* pipefd[0] is opened for reading pipefd[1] is opened for writing */

Page No: 1

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Page No: 2

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

a) Pipes #include<sys/types.h> #include<stdio.h> #include<fcntl.h> #include<unistd.h> int main() { int pfd1[2],pfd2[2],n,fd; //can be used as pfd[2][2]; char fname[512],buff[1024]; pid_t pid; pipe(pfd1); pipe(pfd2); if((pid=fork())<0) { perror("fork() error"); exit(0); }

if(pid==0) //child server { close(pfd1[1]); close(pfd2[0]); n=read(pfd1[0],fname,512); fname[n]=0; printf("SERVER:Accepting request for file name:(%s)\n",fname); if((fd=open(fname,O_RDONLY))<0) { printf("SERVER:No such file:\n"); exit(0); } while((n=read(fd,buff,1024))>0) {

Page No: 3

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

write(pfd2[1],buff,n); } close(pfd1[0]); close(pfd2[1]); exit(0); } //parent client close(pfd1[0]); close(pfd2[1]); printf("Enter File Name:"); scanf("%s",fname); write(pfd1[1],fname,strlen(fname)); printf("CLIENT:Retriving file:(%s)...........\n",fname); while((n=read(pfd2[0],buff,1024))>0) { write(1,buff,n); } close(pfd1[1]); close(pfd2[0]); }

Page No: 4

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec@localhost] cc pipes.c [cmec@localhost] ./a.out CLIENT:Retriving file: (sample.c) SERVER:Accepting request for file name:( sample.c) #include<stdio.h> main() { printf(hello world); }

Page No: 5

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

b) FIFO SERVER PROGRAM


Description:

A unix FIFO is smililar to a pipe. It is one way flow of data with the first byte written to it being the first byte read from it. FIFOs have a name, so unrelated process can share the FIFO. A FIFO is created by mknod system call. Create: A FIFO is created by the mkfifo function: #include <sys/types.h> #include <sys/stat.h>

int mkfifo(const char *pathname, mode_t mode); pathname a UNIX pathname (path and filename). The name of the FIFO mode the file permission bits. FIFO can also be created by the mknod system call, e.g., mknod(fifo1, S_IFIFO|0666, 0) is same as mkfifo(fifo1, 0666).

Open: mkfifo tries to create a new FIFO. If the FIFO already exists, then an EEXIST error is returned. To open an existing FIFO, use open(), fopen() or freopen() Close: to close an open FIFO, use close(). To delete a created FIFO, use unlink().

Page No: 6

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include<stdio.h> #include<string.h> #include<unistd.h> #include<fcntl.h> #include<sys/stat.h> int main() { char fname[25]=" "; char fc[100]=" "; int fd,fd1,fd2; mkfifo("fifo1",0600); mkfifo("fifo2",0600); fd=open("fifo1",O_RDONLY); fd1=open("fifo2",O_WRONLY); read(fd,fname,25); fd2=open(fname,O_RDONLY); while(read(fd2,fc,100)!=0) { printf("%s\n",fc); if(fd<0) write(fd1,"file not exist",14); else write(fd1,fc,strlen(fc)); } close(fd); close(fd1); close(fd2); }

Page No: 7

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: #include<stdio.h> main() { int p[2]; pipe(p); printf(p*0+ is %d\n p[1] is %d\n,p*0+,p*1+); }

Page No: 8

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

FIFO CLIENT PROGRAM #include<stdio.h> #include<string.h> #include<unistd.h> #include<fcntl.h> #include<sys/stat.h> int main() { char s[25]=" "; char s1[100]=" "; int fd,fd1; fd=open("fifo1",O_WRONLY); fd1=open("fifo2",O_RDONLY); printf("enter the filename"); scanf("%s",s); write(fd,s,strlen(s)); while(read(fd1,s1,1000)!=0) printf("file content:%s",s1); }

Page No: 9

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: Enter filename:pipe1.c #include<stdio.h> main() { int p[2]; pipe(p); printf(p*0+ is %d\n p[1] is %d\n,p*0+,p*1+); }

Page No: 10

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week 2: MESSAGE QUEUE SERVER


Aim: To implement a program for file transfer using Message Queue form of IPC.

Description: Drawback of PIPE and FIFO: 1) Pipe or FIFO is an unformatted stream. Message queue is a formatted stream consisted of messages. 2) Pipe or FIFO has to be read in the same order as they are written. Message queue can be accessed randomly. 3) Pipe or FIFO is unidirectional. Message queue is bidirectional. 4) Pipe or FIFO is simplex. Message queue is multiplex. 5) Message queue is faster since it is in kernel. Message format: it can be user-defined. Every message has size (int), i.e., the length of data, type (long int), data (if length > 0).

-- Some Operating system restrict the passing of messages such that a process can only send message to another specific process. --System V has no such restriction ,in the system V implementa

Page No: 11

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

---Length of the data portion of the message (can be 0) ---Data if length is > 0. A message queue is created or opened using: int msgget(key_t key, int msgflag); msgflag sets permission + IPC_CREAT / IPC_EXCL. msgid returned by the msgget() function, -1 on error. Messages are sent using: int msgsnd(int msgid, struct msgbuf *ptr, int length, int flag); struct msgbuf -- message format, has a long int (message type) as a field, immediately followed by the data. Must befilled by caller before calling msgsnd( ). length determine how many bytes of data portion are sent. flag can be IPC_NOWAIT which causes the function to return immediately with error=EAGAIN if no queue space is available. Default action is to block. return 0 if successful; -1 on error. Messages are received using: int msgrev(int msgid, struct msgbuf *ptr, int length, long msgtype, int flag); length specify the size of the data buffer. Error if the message is too long. OK if the length message length which is determined by msgsnd(length).

Page No: 12

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

flag if set to MSG_NOERROR, long messages are truncated and the rest is discarded. If set to IPC_NOWAIT, function return 1 if no matching messages are found, otherwise block until A message with the appropriate type is placed on the queue. The message queue is removed from the system. The process receives a signal that is not ignored. msgtype = 0: read the first msg on the queue. >0: read the first msg on the queue with this type. <0: read the first msg on the queue with the lowest type | msgtype| return the length of the data received in bytes if successful; -1 on error.

Control operations use: int msgctl(int msgid, int cmd, struct msg-id-ds *buff) To remove a msg queue, cmd = IPC_RMID; the 3rd parameter is just a NULL pointer. To get/set the queue information in buff, cmd = IPC-STAT/IPC-SET.

Page No: 13

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include<stdio.h> #include<string.h> #include<sys/types.h> #include<sys/msg.h> #include<sys/ipc.h> int main() { key_t ipckey; int mq_id; struct { long type; char text[100]; }mymsg; ipckey=ftok("msgq_server.c",42); printf("My key is %d\n",ipckey); mq_id=msgget(ipckey,IPC_CREAT|0666); printf("message identifier is %d\n",mq_id); memset(mymsg.text,0,100); strcpy(mymsg.text,"Hello world!"); mymsg.type=1; msgsnd(mq_id,&mymsg,sizeof(mymsg),0); }

Page No: 14

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: My key is 704643998 Message identifier is 32769

Page No: 15

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

MESSAGE QUEUE CLIENT Program: #include<stdio.h> #include<string.h> #include<sys/types.h> #include<sys/msg.h> #include<sys/ipc.h> int main() { key_t ipckey; int mq_id,rec; struct { long type; char text[100]; }mymsg; ipckey=ftok("msgq_server.c",42); printf("My key is %d\n",ipckey); mq_id=msgget(ipckey,0); printf("message identifier is %d\n",mq_id); rec=msgrcv(mq_id,&mymsg,sizeof(mymsg),0,0); printf("%s %d\n",mymsg.text,rec); }

Page No: 16

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: My key is 704643998 Message identifier is 32769 Hello world! 104

Week 3:

Page No: 17

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

SHARED MEMORY: AIM: To implement shared memory concept and increment the variable simultaneously by two processes Description: Semaphores are not used to exchange a large amount of data. Semaphores are used synchronization among processes. Other synchronization mechanisms include record locking and mutexes. Examples include: shared washroom, common rail segment, and common bank account. 1) The semaphore is stored in the kernel: Allows atomic operations on the semaphore processes are prevented from indirectly modifying the value. 2) A process acquires the semaphore if it has a value of zero. The value of the semaphore is then incremented toWhen a process releases the semaphore, the value of the semaphore is decremented. 3) If the semaphore has non-zero value when a process tries to acquire it, that process blocks. 4) In comments 2 and 3, the semaphore acts as a customer counter. In most cases, it is a resource counter. 5) When a process waits for a semaphore, the kernel puts the process to sleep until the semaphore is available. This is better (more efficient) than busy waiting such as TEST&SET. 6) The kernel maintains information on each semaphore internally, using a data structure struct semis_ds that keeps track of permission, number of semaphores, etc. 7) Apparently, a semaphore in UNIX is not a single binary value, but a set of nonnegative integer values

Page No: 18

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include<stdio.h> #include<string.h> #include<unistd.h> #include<errno.h> #include<sys/types.h> #include<sys/ipc.h> #include<sys/shm.h> int main() { pid_t pid; int *shared; int shmid; shmid=shmget(IPC_PRIVATE,sizeof(int),IPC_CREAT|0666); printf("SHARED MEMORY ID=%u \n",shmid); if(fork()==0){ shared=shmat(shmid,(void *)0,0); printf("child pointer:%u\n",shared); *shared=1; printf("child value=%d\n",*shared); sleep(2); printf("child value=%d\n",*shared); } else { shared=shmat(shmid,(void *)0,0); printf("parent pointer:%u\n",shared); printf("parent value=%d\n",*shared); sleep(1); *shared=42; printf("parent value=%d\n",*shared); sleep(5); shmctl(shmid,IPC_RMID,0); }

Page No: 19

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

} Output: Shared memory id=622 603 Child pointer 3086576224 Child value=1 Shared memory id=622 603 Parent pointer 3086516224 Parent value=1 Parent value=42 Child value=42

Page No: 20

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week 4: TCP ECHO SERVER


Aim: To design TCP iterative client and server application to echo a given sentence.

Description:

1. The client reads a line of text from its standard inputs and writes the lines to the server. 2. The server reads the line from its network input and echoes the line back to the client. 3. The client reads the echoed line and prints it on its standard output.

fgets stdin stdout fputs

Tcp client

writen

read

Tcp server

FVGY

readline

writen

Page No: 21

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include<stdio.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<fcntl.h> main() { int sd,cd,i,k,a=0; char buff[100]=" ",temp[100]; struct sockaddr_in ser; sd=socket(AF_INET,SOCK_STREAM,0); if(sd<0) printf("socket connection failed"); bzero(&ser,sizeof(ser)); ser.sin_family=AF_INET; ser.sin_port=htons(1035); inet_aton("192.168.1.1",&ser.sin_addr); int b=bind(sd,(struct sockaddr *)&ser,sizeof(ser)); printf("bind =%d\n",b); listen(sd,5); for(; ;) { cd=accept(sd,NULL,NULL); printf("accept =%d\n",cd); read(cd,buff,100); printf("MESSAGE FROM CLIENT:%s\n",buff); write(cd,buff,strlen(buff)); close(cd); } close(sd); }

Page No: 22

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec @localhost]# cc echotcp_server.c [cmec @localhost]# ./a.out Bind=0 Accept=4 Message from client: welcome to cmec

Page No: 23

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

TCP ECHO CLIENT Program: #include<stdio.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<fcntl.h> main() { int sd,cd; char buff[100]=" ",buff1[100]=" "; struct sockaddr_in ser; sd=socket(AF_INET,SOCK_STREAM,0); if(sd<0) printf("socket connection failed"); bzero(&ser,sizeof(ser)); ser.sin_family=AF_INET; ser.sin_port=htons(1035); inet_aton("192.168.1.1",&ser.sin_addr); int c=connect(sd,(struct sockaddr *)&ser,sizeof(ser)); printf("CONNECT =%d\n",c); if(c<0) printf("CONNECTION FAILED\n"); printf("enter the message:"); scanf("%s",buff); write(sd,buff,strlen(buff)); read(sd,buff1,100); printf("received from server:%s\n",buff1); close(c); close(sd); }

Page No: 24

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec @localhost]#cc echotcp_client.c [cmec @localhost]#./a.out Connect 0 Enter the message: welcome to cmec Received from server: welcome to cmec

Page No: 25

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

WEEK 5: TCP REVERSE SERVER:


Aim: To design TCP iterative client and server application to reverse the given input sentence.

Description:

1. The client reads a line of text from its standard inputs and writes the lines to the server. 2. The server reads the line from its network input and reverse the line and prints it on its standard output.

fgets

Tcp client

writen

read

Tcp server

fputs

stdin

stdout

Page No: 26

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include<stdio.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<fcntl.h> main() { int sd,cd,i,k,a=0; char buff[100]=" ",temp[100]; struct sockaddr_in ser; sd=socket(AF_INET,SOCK_STREAM,0); if(sd<0) printf("socket connection failed"); bzero(&ser,sizeof(ser)); ser.sin_family=AF_INET; ser.sin_port=htons(1050); inet_aton("192.168.1.1",&ser.sin_addr); int b=bind(sd,(struct sockaddr *)&ser,sizeof(ser)); printf("bind =%d\n",b); listen(sd,5); for(; ;) { cd=accept(sd,NULL,NULL); printf("accept =%d\n",cd); read(cd,buff,100); printf("MESSAGE FROM CLIENT:%s\n",buff); k=strlen(buff); for(i=k-1;i>=0;i--) temp[a++]=buff[i]; temp[a]='\0';

Page No: 27

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

write(cd,temp,strlen(temp)); printf("rev is %s\n",temp); close(cd); } close(sd); }

Page No: 28

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec @localhost]# cc tcpserver_reverse.c [cmec @localhost]# ./a.out Bind=0 Accept=4 Message from client: hello world Rev is dlrow olleh

Page No: 29

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

TCP REVERSE CLIENT Program: #include<stdio.h> #include<string.h> #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<arpa/inet.h> #include<fcntl.h> main(){ int sd,cd; char buff[100]=" ",buff1[100]=" "; struct sockaddr_in ser; sd=socket(AF_INET,SOCK_STREAM,0); if(sd<0) printf("socket connection failed"); bzero(&ser,sizeof(ser)); ser.sin_family=AF_INET; ser.sin_port=htons(1050); inet_aton("192.168.1.1",&ser.sin_addr); int c=connect(sd,(struct sockaddr *)&ser,sizeof(ser)); printf("CONNECT =%d\n",c); if(c<0) printf("CONNECTION FAILED\n"); printf("enter the message:"); scanf("%s",buff); write(sd,buff,strlen(buff)); read(sd,buff1,100); close(c); close(sd); }

Page No: 30

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec @localhost]# cc tcpclient_reverse.c [cmec @localhost]# ./a.out Connect=0 Enter the message: hello world

Page No: 31

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week 6: TCP FILE TRANSFER SERVER


Aim: To design TCP iterative client and server application to transfer a file.

Description: 1. The client reads a file name from its standard inputs and writes its to the server. 2. The server reads the file name from its network input and prints it in server.

fgets

Tcp client

writen

read

Tcp server

fputs

stdin

stdout

Page No: 32

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include "header.h" #define LISTENQ 5 #define MAXSIZE 1024 #define PORT 1030 int main(int argc, char *argv[]) { void file_server(int ); struct sockaddr_in client, server; int listenfd,connfd; socklen_t clilen; pid_t childpid; if((listenfd = socket(AF_INET,SOCK_STREAM,0))<0) { perror("socket error"); exit(-1); } bzero(&server,sizeof(server)); server.sin_family = AF_INET; server.sin_addr.s_addr = htonl(INADDR_ANY); server.sin_port = htons(1030); if(bind(listenfd,(struct sockaddr *)&server, sizeof(server))<0) { perror("bind error()"); exit(-1); } if(listen(listenfd, LISTENQ)<0) { perror("listen error()"); exit(-1); } for(;;) {

Page No: 33

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

clilen = sizeof(client); if((connfd = accept(listenfd,(struct sockaddr *)&client, &clilen))<0) { perror("accept error()"); exit(-1); } /* CONCURRENT SERVER */ if((childpid=fork()) == 0) { close(listenfd); file_server(connfd); close(connfd); exit(0); } /*str_echo(connfd); */ close(connfd); } exit(0); } void file_server(int sockfd) { char data[MAXSIZE]; char revdata[MAXSIZE]; int fd; int n; if((n=read(sockfd,data,MAXSIZE))<0) { perror("read error()"); exit(-1); } data[n]='\0'; printf("filename = %s \n ",data); if((fd=open(data,O_RDONLY))<0) { sprintf(revdata,"file %s doesn't exist \n",data);

Page No: 34

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

write(sockfd,revdata,strlen(revdata)); } else while((n=read(fd,revdata,MAXSIZE))>0) { write(sockfd,revdata,n); } close(fd); }

Page No: 35

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: [cmec @localhost]# cc tcpfile_server.c [cmec @localhost]# ./a.out pipes.c #include <stdio.h> #include<sys/types.h> #include<stdlib.h> main() { pid_t pid; pid=fork(); if(pid==0) printf(child active); else pritnf(parent active); }

Page No: 36

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

TCP FILE TRANSFER CLIENT Program: #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <unistd.h> #include <math.h> #include <string.h> #include <arpa/inet.h> #include <fcntl.h> #define MAXSIZE 1024 int main(int argc, char *argv[]) { struct sockaddr_in server; int sockfd,p; void file_client(FILE *,int ); if(argc != 3) { printf("Usage : ./a.out <IP-ADDR> <PORT_NO>"); exit(-1); } if((sockfd = socket(AF_INET, SOCK_STREAM, 0))<0) { perror("socket() error"); exit(0);

Page No: 37

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

} bzero(&server, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(atoi(argv[2])); // inet_pton(AF_INET, argv[1], (void *)&server.sin_addr); server.sin_addr.s_addr=inet_addr(argv[1]); if((connect(sockfd,(struct sockaddr *)&server, sizeof (server)))<0) { perror(" Connect() error "); exit(-1); } file_client(stdin,sockfd); close(sockfd); exit(0); } void file_client(FILE *fp,int sockfd) { int n,i; char sdata[MAXSIZE],rdata[MAXSIZE]; while(fgets(sdata,MAXSIZE,fp)!=NULL) { sdata[strlen(sdata)-1]='\0'; if(strcmp(sdata,"")!=0) break; } write(sockfd,sdata,strlen(sdata)); while((n=read(sockfd,rdata,MAXSIZE)) > 0) write(1,rdata,n); }

Page No: 38

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec @localhost]# cc tcpfile_client.c [cmec @localhost]#./a.out Filename=pipes.c

Page No: 39

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week 7: TCP CONCURRENT SERVER Program: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/select.h> #include <sys/time.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #define MAXLINE 100 #define SERV_PORT 13153 int main(int argc, char **argv) { int k, i, maxi, maxfd, listenfd, connfd, sockfd; int nready, client[FD_SETSIZE]; ssize_t n; fd_set rset, allset; char line[MAXLINE],buf[100]; socklen_t clilen; struct sockaddr_in cliaddr, servaddr; listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd < 0 ) { perror("socket" ); exit(1); }

Page No: 40

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(SERV_PORT); bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); listen(listenfd,5); maxfd = listenfd; maxi = -1; for (i = 0; i < FD_SETSIZE; i++) client[i] = -1; FD_ZERO(&allset); FD_SET(listenfd, &allset); for ( ; ; ) { printf("Server:I am waiting-----Start of Main Loop\n"); rset = allset; nready = select(maxfd+1, &rset, NULL, NULL, NULL); if (FD_ISSET(listenfd, &rset)) clilen = sizeof(cliaddr); connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen); #ifdef NOTDEF printf("new client: %s, port %d\n", inet_ntop(AF_INET, &cliaddr.sin_addr, buf, NULL), ntohs(cliaddr.sin_port)); #endif for (i = 0; i < FD_SETSIZE; i++) if (client[i] < 0) { client[i] = connfd; /* save descriptor */ break; } if (i == FD_SETSIZE) { printf("too many clients"); exit(0);

Page No: 41

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

} FD_SET(connfd, &allset); if (connfd > maxfd) maxfd = connfd; if (i > maxi) maxi = i; if (--nready <= 0) 26 continue; } for (i = 0; i <= maxi; i++) { if ( (sockfd = client[i]) < 0) continue; if (FD_ISSET(sockfd, &rset)) { if ( (n = read(sockfd, line, MAXLINE)) == 0) { close(sockfd); FD_CLR(sockfd, &allset); client[i] = -1; } else { printf("\n output at server\n"); for(k=0;line[k]!='\0';k++) printf("%c",toupper(line[k])); write(sockfd, line, n); } if (--nready <= 0) break; } } } }

Page No: 42

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: [cmec@localhost ]# cc tcpservselect01.c [cmec@localhost]#./a.out Server:I am waiting-----Start of Main Loop output at server ABCD Server:I am waiting-----Start of Main Loop

Page No: 43

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

TCP CONCURRENT CLIENT: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #define MAXBUFFER 1024 void sendstring(int , char *); int main( int C, char *V[] ) { int sd,fd; char c; struct sockaddr_in serveraddress; char text[100]; int i=0; sd = socket( AF_INET, SOCK_STREAM, 0 ); if( sd < 0 ) { perror( "socket" ); exit( 1 ); } if (V[1] == NULL ) { printf ("PL specfiy the server's IP Address \n"); exit(0); } if (V[2] == NULL ) { printf ("PL specify the server's Port No \n"); exit(0);

Page No: 44

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

} if (V[3] == NULL ) { printf ("PL specfiy the string to be send to the server \n"); exit(0); } memset( &serveraddress, 0, sizeof(serveraddress) ); serveraddress.sin_family = AF_INET; serveraddress.sin_port = htons(atoi(V[2]));//PORT NO serveraddress.sin_addr.s_addr = inet_addr(V[1]);//ADDRESS if (connect(sd,(struct sockaddr*)&serveraddress, sizeof(serveraddress))<0) { printf("Cannot Connect to server"); exit(1); } printf("enter sentence to end enter #"); while(1) { c=getchar(); if(c=='#') break; text[i++]=c; } text[i]='\0'; sendstring(sd,text); close(sd); return 0; } void sendstring(int sd,char *fname) { int n , byteswritten=0 , written ; char buffer[MAXBUFFER]; strcpy(buffer , fname);

Page No: 45

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

n=strlen(buffer); while (byteswritten<n) { written=write(sd , buffer+byteswritten,(n-byteswritten)); byteswritten+=written; 29 } printf("String : %s sent to server \n",buffer); }

Page No: 46

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: [cmec @ localhost]# cc tcpcliselect [cmec@localhost ]# ./a.out 192.168.1.1 13153 enter sentence to end enter #abcd# String : abcd sent to server

Page No: 47

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

WEEK8: TCP CONCURRENT SERVER POLL FUNCTION Program: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include <limits.h> /* for OPEN_MAX */ #include <poll.h> #include <errno.h> #define MAXLINE 100 #define SERV_PORT 13154 #define POLLRDNORM 5 #define INFTIM 5 #define OPEN_MAX 5 int main(int argc, char **argv){ int k, i, maxi, listenfd, connfd, sockfd; int nready; ssize_t n; char line[MAXLINE]; socklen_t clilen; struct pollfd client[OPEN_MAX]; struct sockaddr_in cliaddr, servaddr; listenfd = socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(SERV_PORT); bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr));

Page No: 48

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

listen(listenfd, 5); 31 client[0].fd = listenfd; client[0].events = POLLRDNORM; for (i = 1; i < OPEN_MAX; i++) client[i].fd = -1; /* -1 indicates available entry */ maxi = 0; /* max index into client[] array */ /* end fig01 */ /* include fig02 */ for ( ; ; ) { nready = poll(client, maxi+1, INFTIM); if (client[0].revents & POLLRDNORM) { /* new client connection */ clilen = sizeof(cliaddr); connfd = accept(listenfd, (struct sockaddr *) &cliaddr, &clilen); #ifdef NOTDEF printf("new client: %s\n", sock_ntop((struct sockaddr *) &cliaddr, clilen)); #endif for (i = 1; i < OPEN_MAX; i++) if (client[i].fd < 0) { client[i].fd = connfd; /* save descriptor */ break; } if (i == OPEN_MAX){ printf("too many clients"); exit(0); } client[i].events = POLLRDNORM; if (i > maxi) maxi = i; /* max index in client[] array */ if (--nready <= 0) continue; /* no more readable descriptors */ }

Page No: 49

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

for (i = 1; i <= maxi; i++) { /* check all clients for data */ if ( (sockfd = client[i].fd) < 0) 32 continue; if (client[i].revents & (POLLRDNORM | POLLERR)) { if ( (n = read(sockfd, line, MAXLINE)) < 0) { if (errno == ECONNRESET) { /*4connection reset by client */ #ifdef NOTDEF printf("client[%d] aborted connection\n", i); #endif close(sockfd); client[i].fd = -1; } else printf("readline error"); } else if (n == 0) { /*4connection closed by client */ #ifdef NOTDEF printf("client[%d] closed connection\n", i); #endif close(sockfd); client[i].fd = -1; } else{ printf("\n data from client is \n"); k=strlen(line); printf(" length=%d data = %s\n", k,line); //write(sockfd, line, n); strcpy(line," "); } if (--nready <= 0) break; /* no more readable descriptors*/ } } } }

Page No: 50

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: [cmec@localhost ]# cc tcpservpoll01.c [cmec@localhost ]# ./a.out data from client is data = aaaaaaaaaaaaaaaaaaaaaaaa

Page No: 51

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

TCP CLIENT: democlient.c /***************************************************************** ********** * FILENAME : democlient.c * DESCRIPTION:Contains Code for a client that will send a string * to a server process and exits. * Invoke the Executable as a.out IPAddress PortNo string ****************************************************************** ***********/ Program: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #define MAXBUFFER 1024 void sendstring(int , char *); int main( int C, char *V[] ) { int sd,fd; char c; struct sockaddr_in serveraddress; char text[100]; int i=0; sd = socket( AF_INET, SOCK_STREAM, 0 );

Page No: 52

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

if( sd < 0 ) { perror( "socket" ); exit( 1 ); } if (V[1] == NULL ) { printf ("PL specfiy the server's IP Address \n"); exit(0); } if (V[2] == NULL ) { printf ("PL specify the server's Port No \n"); exit(0); } // if (V[3] == NULL ) { 34 // printf ("PL specfiy the string to be send to the server \n"); // exit(0); // } memset( &serveraddress, 0, sizeof(serveraddress) ); serveraddress.sin_family = AF_INET; serveraddress.sin_port = htons(atoi(V[2]));//PORT NO serveraddress.sin_addr.s_addr = inet_addr(V[1]);//ADDRESS if (connect(sd,(struct sockaddr*)&serveraddress, sizeof(serveraddress))<0) { printf("Cannot Connect to server"); exit(1); } printf("enter sentence to end enter #"); while(1) { c=getchar(); if(c=='#') break; text[i++]=c;

Page No: 53

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

} text[i]='\0'; sendstring(sd,text); close(sd); return 0; } /***************************************************************** ******* * FUNCTION NAME:sendstring * DESCRIPTION: sends a string over the socket . * NOTES : No Error Checking is done . * RETURNS :void ****************************************************************** ******/ void sendstring( int sd, /*Socket Descriptor*/ char *fname) /*Array Containing the string */ { int n , byteswritten=0 , written ; char buffer[MAXBUFFER]; strcpy(buffer , fname); n=strlen(buffer); while (byteswritten<n) { written=write(sd , buffer+byteswritten,(n-byteswritten)); 35 byteswritten+=written; } printf("String : %s sent to server \n",buffer); }

Page No: 54

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: [cmec@localhost ]# cc tcpservpoll01.c [cmec@localhost ]# ./a.out 192.168.1.1 13154 enter sentence to end enter #aaaaaaaaaaaaaaaaaaaaaaaa# String aaaaaaaaaaaaaaaaaaaaaaaa sent to server

Page No: 55

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

WEEK 9:
Aim: To design UDP iterative client and server application to echo a given string.

Description:

1. The client reads a line of text from its standard inputs and sends it to the server using the function sendto. 2. The server receives the line from its network input using the function recvfrom and echoes the line back to the client. 3. The client reads the echoed line and prints it on its standard output.

fgets stdin stdout fputs

UDP client

sendto

recvfrom

UDP server

FVGY

recvfrom

sendto

Page No: 56

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: #include<netinet/in.h> #include<sys/types.h> #include<sys/socket.h> #include<stdio.h> #include<arpa/inet.h> #include<string.h> #include<fcntl.h> main() { int sfd,l; char buf[100]=" "; struct sockaddr_in ser,cli; sfd=socket(AF_INET,SOCK_DGRAM,0); bzero(&ser,sizeof(ser)); ser.sin_family=AF_INET; ser.sin_port=htons(2030); inet_aton("192.168.1.1",&ser.sin_addr); printf("bind=%d\n",bind(sfd,(struct sockaddr*)&ser,sizeof(ser))); l=sizeof(cli); for(; ;) { recvfrom(sfd,buf,100,0,(struct sockaddr*)&cli,&l); sendto(sfd,buf,strlen(buf),0,(struct sockaddr *)&cli,l); printf("message from client :%s\n",buf); } }

Page No: 57

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec@localhost] cc udpecho_server.c [cmec@localhost] ./a.out Bind=0 Message from client: welcome

Page No: 58

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

UDP ECHO CLIENT Program: #include<netinet/in.h> #include<sys/types.h> #include<sys/socket.h> #include<stdio.h> #include<arpa/inet.h> #include<string.h> #include<fcntl.h> main() { int sfd,l; char buf[100]=" ",buf1[100]=" "; struct sockaddr_in ser; sfd=socket(AF_INET,SOCK_DGRAM,0); bzero(&ser,sizeof(ser)); ser.sin_family=AF_INET; ser.sin_port=htons(2030); inet_aton("192.168.1.1",&ser.sin_addr); printf(" enter message:"); scanf("%s",buf); sendto(sfd,buf,strlen(buf),0,(struct sockaddr*)&ser,sizeof(ser)); recvfrom(sfd,buf1,100,0,NULL,NULL); printf(" echo from server:%s\n ", buf1); close(sfd); }

Page No: 59

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Output: [cmec@localhost] cc udpecho_client.c [cmec@localhost] ./a.out Enter message: welcome Echo from server:welcome

Page No: 60

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week 10: UDP SERVER REVERSE


Aim: To design UDP client/server to reverse the given input sentence.

Description: 1. The client reads a line of text from its standard input and sends it to the server using sendto. 2. The server receives the line from its network input using recvfrom and reverse the line and prints it on its standard output.

fgets

UDP client

sendto

recvfrom

UDP server

fputs

stdin

stdout

Page No: 61

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Program: /***************************************************************** ************* * FILENAME : uechos.c * DESCRIPTION:Contains Code for a echo server , that will accept data * from a client process and sends that data back to client, using UDP * Invoke the Executable as a.out ****************************************************************** ************/ #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/wait.h> #include <fcntl.h> #include <signal.h> #define BUFSIZE 512 #define MYPORT 11710 #define MAXNAME 100 int main(int C, char **V ) { int sd,n,ret; struct sockaddr_in 38 serveraddress,cliaddr; socklen_t length; char clientname[MAXNAME],datareceived[BUFSIZE]; sd = socket( AF_INET, SOCK_DGRAM, 0 ); if( sd < 0 ) { perror( "socket" );

Page No: 62

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

exit( 1 ); } memset( &serveraddress, 0, sizeof(serveraddress) ); memset( &cliaddr, 0, sizeof(cliaddr) ); serveraddress.sin_family = AF_INET; serveraddress.sin_port = htons(MYPORT);//PORT NO serveraddress.sin_addr.s_addr = htonl(INADDR_ANY);//IP ADDRESS ret=bind(sd,(struct sockaddr*)&serveraddress,sizeof(serveraddress)); if(ret<0) { perror("BIND FAILS"); exit(1); } for(;;) { printf("I am waiting\n"); /*Received a datagram*/ length=sizeof(cliaddr); n=recvfrom(sd,datareceived,BUFSIZE,0, (struct sockaddr*)&cliaddr , &length); printf("Data Received from %s\n", inet_ntop(AF_INET,&cliaddr.sin_addr, clientname,sizeof(clientname))); /*Sending the Received datagram back*/ datareceived[n]='\0'; printf("I have received %s\n",datareceived); sendto(sd,datareceived,n,0,(struct sockaddr *)&cliaddr,length); } }

Page No: 63

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: UDP Client Server Application. Compiling and running server. [cmec@localhost ]$ cc udp_server.c [cmec @localhost]$ ./a.out I am waiting Data Received from 192.168.1.1 I have received abcd efgh rev is hgfe dcba I am waiting

Page No: 64

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

UDP CLIENT REVERSE /***************************************************************** ********** * FILENAME : uechoc.c * DESCRIPTION:Contains Code for a echo client , that will accept data * from the user(keyboard) and sens that data to a echo server process * and prints the received data back on the screen .(UDP) * Invoke the Executable as a.out ServerIP ServerPort ****************************************************************** **********/ Program: #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include <signal.h> #include <unistd.h> #define BUFSIZE 512 static void sig_usr(int); void str_cli(FILE *fp , int sockfd , struct sockaddr *server , socklen_t len); int main( int C, char *argv[] ) { int sd; struct sockaddr_in serveraddress; /*Installing signal Handlers*/ signal(SIGPIPE,sig_usr); signal(SIGINT,sig_usr);

Page No: 65

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

if (NULL==argv[1]) { printf("Please enter the IP Address of the server\n"); exit(0); } if (NULL==argv[2]) { printf("Please enter the Port Number of the server\n"); exit(0); } sd = socket( AF_INET, SOCK_DGRAM, 0 ); if( sd < 0 ) { perror( "socket" ); exit( 1 ); } memset( &serveraddress, 0, sizeof(serveraddress) ); serveraddress.sin_family = AF_INET; serveraddress.sin_port = htons(atoi(argv[2]));//PORT NO serveraddress.sin_addr.s_addr = inet_addr(argv[1]);//ADDRESS printf("Client Starting service\n"); printf("Enter Data For the server\n"); str_cli(stdin,sd ,(struct sockaddr *)&serveraddress, sizeof(serveraddress)); }

/***************************************************************** ******* * FUNCTION NAME:sig_usr * DESCRIPTION: Signal Handler for Trappinf SIGPIPE

Page No: 66

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

* NOTES : No Error Checking is done . * RETURNS :void ****************************************************************** ******/ static void sig_usr( int signo) /*Signal Number*/ /***************************************************************** *******/ { char *strpipe="RECEIVED SIGPIPE - ERROR"; char *strctrl="RECEIVED CTRL-C FROM YOU"; if(signo==SIGPIPE){ write(1,strpipe,strlen(strpipe)); exit(1); } else if(signo==SIGINT) { write(1,strctrl,strlen(strctrl)); exit(1); } } /***************************************************************** ******* * FUNCTION NAME:str_cli * DESCRIPTION: Main Client Processing (Select waits for readiness of * connection socket or stdin * NOTES : No Error Checking is done . * RETURNS :void ****************************************************************** ******/ void str_cli(FILE *fp, /*Here to be used as stdin as argument*/ int sockfd , struct sockaddr *to ,socklen_t length) /*Connection Socket */

Page No: 67

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

/***************************************************************** ******/ { int maxdes,n; fd_set rset; char sendbuf[BUFSIZE] , recvbuf[BUFSIZE] ,servername[100]; struct sockaddr_in serveraddr; socklen_t slen; FD_ZERO(&rset); maxdes=(sockfd>fileno(fp)?sockfd+1:fileno(fp)+1); for(;;){ FD_SET(fileno(fp) , &rset); FD_SET(sockfd , &rset); select(maxdes,&rset,NULL,NULL,NULL); if(FD_ISSET(sockfd , & rset)){ slen=sizeof(serveraddr); n=recvfrom(sockfd,recvbuf,BUFSIZE,0, (struct sockaddr*)&serveraddr,&slen); printf("Data Received from server %s:\n", inet_ntop(AF_INET,&serveraddr.sin_addr, servername,sizeof(servername))); write(1,recvbuf,n); printf("Enter Data For the server\n"); } if(FD_ISSET(fileno(fp) , & rset)){ /*Reading data from the keyboard*/ fgets(sendbuf,BUFSIZE,fp); n = strlen (sendbuf); /*Sending the read data over socket*/ sendto(sockfd,sendbuf,n,0,to,length); printf("Data Sent To Server\n"); } } }

Page No: 68

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: Compiling and running client. cmec @localhost ]$ cc udp_client.c [cmec @localhost ]$ ./.a.out 192.168.1.1 11710 Client Starting service Enter Data For the server abcd efgh Data Sent To Server Data Received from server 192.168.1.1: abcd efgh Enter Data For the server

Page No: 69

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

Week11: Design a RPC application to add and subtract a given pair of integers Step 1: First create RPC specification file with .x extension which defines the server procedure along with their arguments and results. The following program shows the contents of Filename : rpctime.x.

/****************************************************************** **/ /*** rpctime.x */ /*** SPECIFICATION FILE TO DEFINE SERVER PROCEDURE AND ARGUMENTS ***/ /****************************************************************** **/ program RPCTIME { version RPCTIMEVERSION { long GETTIME() = 1; } = 1; } = 2000001;

Step 2: /*Server*/

Page No: 70

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

The following program shows the contents of Filename : rpctime_server.c #include "rpctime.h" long *gettime_1_svc(void *argp, struct svc_req *rqstp) { static long result; time(&result); return &result; }

Step 3:

/*Client*/ The following program shows the contents of Filename : rpctime_client.c #include "rpctime.h" Void rpctime_1(char *host) { CLIENT *clnt; long *result_1; char *gettime_1_arg; #ifndef DEBUG

Page No: 71

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

clnt = clnt_create (host, RPCTIME, RPCTIMEVERSION, "udp"); if (clnt == NULL) { clnt_pcreateerror (host); exit (1); } #endif /* DEBUG */ result_1 = gettime_1((void*)&gettime_1_arg, clnt); if (result_1 == (long *) NULL) { clnt_perror (clnt, "call failed"); } else printf("%d |%s", *result_1, ctime(result_1)); #ifndef DEBUG clnt_destroy (clnt); #endif /* DEBUG */ } int main (int argc, char *argv[]) { char *host; if (argc < 2) { printf ("usage: %s server_host\n", argv[0]); exit (1); } host = argv[1]; rpctime_1 (host); exit (0); }

Page No: 72

CMEC

Name: G S GOUTHAM KUMAR Roll no: 08Q91A0579

Date: Exp no:

OUTPUT: Step 1: [cmec@localhost $]$ rpcgen C rpctime.x. This creates rpctime.h, rpctime_clnt.c, rpctime_svc.c files in the folder Step 2: [cmec@localhost $]$cc c rpctime_client.c o rpctime_clien.o Step 3: [cmec localhost $]$cc o client rpctime_client.o rpctime_clnt.o lnsl Step 4: [cmec @localhost $]$cc c rpctime_server.c o rpctime_server.o Step 5: [cmec @localhost $]$cc o server rpctime_server.o rpctime_svc.o -lnsl [root @localhost $]$./server & [1] 7610 [root @localhost $]$./client 127.0.0.1 1277628700 |Sun Jun 27 14:21:40 2010 [root @localhost $]$./client 127.0.0.1 1277628718 |Sun Jun 27 14:21:58 2010

Page No: 73

CMEC

You might also like