IV YEAR B.

Tech

Network Programming

Prepared By
R.Venkata Subbaiah BE.M.Tech.
Associate Professor IC RNEC@Development Cell

Department of CSE
RAO & NAIDU ENGINEERING COLLEGE

ONGOLE

NP Lab Manual , RNEC For more Details access portals :

Page |1 ravinuthalavs.webs.com Ravinuthalavs.blogspot.com

Network Programming
Introduction to Inter process Communication : Pipes
Introduction: There are two types of pipes for two-way communication: anonymous pipes and named pipes. Anonymous pipes enable related processes to transfer information to each other. Typically, an anonymous pipe is used for redirecting the standard input or output of a child process so that it can exchange data with its parent process. To exchange data in both directions (duplex operation), you must create two anonymous pipes. The parent process writes data to one pipe using its write handle, while the child process reads the data from that pipe using its read handle. Similarly, the child process writes data to the other pipe and the parent process reads from it. Anonymous pipes cannot be used over a network, nor can they be used between unrelated processes. Properties of Pipe: 1) Pipes do not have a name. For this reason, the processes must share a parent process. This is the main drawback to pipes. However, pipes are treated as file descriptors, so the pipes remain open even after fork and exec. 2) Pipes do not distinguish between messages; they just read a fixed number of bytes. Newline (\n) can be used to separate messages. A structure with a length field can be used for message containing binary data. 3) Pipes can also be used to get the output of a command or to provide input to a command. Creation of Pipes Since A pipe provides a one-way flow of data. Int pipe (int * filedes); Int pipefd[2]; /* pipefd[0] is opened for reading;pipefd[1] is opened for writing */

NP Lab Manual , RNEC For more Details access portals :

Page |2 ravinuthalavs.webs.com Ravinuthalavs.blogspot.com

I
o after call to fork

I
o after both calls to dup2

NP Lab Manual , RNEC For more Details access portals :

Page |3 ravinuthalavs.webs.com Ravinuthalavs.blogspot.com

com Ravinuthalavs.com . it should close fd1. If the parent wants to send data to the child. we should always be sure to close the end of pipe we aren't concerned with. the EOF will never be returned if the unnecessary ends of the pipe are not explicitly closed. it should close fd0. and the child should close fd1.webs. On a technical note.o after all calls to close If the parent wants to receive data from the child.blogspot. and the child should close fd0. Since descriptors are shared between the parent and child. RNEC For more Details access portals : Page |4 ravinuthalavs. NP Lab Manual .

h> # define MAXLINE 4096 int main() { int n. if(pipe(fd)<0) perror("pipe error..h> # include <sys/types. $ cc pipe. char line[MAXLINE].line. pid_t pid. write(1. $ pipe */ page: 5 NP Lab Manual . RNEC .h> # include <stdlib.. } else { close(fd[1]). n=read(fd[0]. } exit(0)..12).c – o pipe Execution………….n). write(fd[1]."Hello world\n".WEEK 1: Aim: Implement the pipe using fork () /* file name pipe.c */ # include <stdio. } /* Compiling…………..MAXLINE). else if(pid>0) { close(fd[0]).line.").").fd[2]. if((pid=fork())<0) perror("fork error.

RNEC page: 6 .Output: [student@localhost ~]$ vi pipe./pipe Hello world NP Lab Manual .c [student@localhost ~]$ cc pipe.c -o pipe [student@localhost ~]$ .

} NP Lab Manual . if(pclose(fpout)==-1) perror("pclose error.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. exit(0). if(argc!=2) { perror("\n usage :.h> # define MAXLINE 4096 # define PAGER "${PAGER:-more}" int main(int argc.").h> # include <stdlib. } if(ferror(fpin)) perror("fgets error.fpout)==EOF) perror("\n fput error...c */ # include <sys/wait.").fpin)) { if(fputs(line.out <path name>").*fpout.").. FILE *fpin."r"))==NULL) { printf("\nUnable to open %s".char*argv[]) { char line[MAXLINE]. RNEC page: 7 .E WEEK 2: Year : Semester: 2010 First Aim: Implement the pipe using popen (). close () /* file name pipeopen.")... } if((fpout=popen(PAGER."w"))==NULL) perror("popen error...argv[1]).MAXLINE.h> # include <stdio. while(fgets(line.S.a. exit(0). } if((fpin=fopen(argv[1].

$ cc pipeopen./* Compiling………….. RNEC page: 8 . $ pipeopen <file with path > */ NP Lab Manual .c – o pipeopen Execution………….

RNEC page: 9 .txt This is the simple text in myfile To create a file: $cat > filename NP Lab Manual .c [student@localhost ~]$ cc pipeopen./pipeopen myfile.Output: [student@localhost ~]$ vi pipeopen.c -o pipeopen [student@localhost ~]$ .

O_WRONLY). /*creating FIFO */ if((mkfifo(". } /* Compiling………….h> # include <fcntl. $ cc makefifo.S.E Year : Semester: 2010 First Aim: Implement the FIFO form of IPC /* file name makefifo.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C./MyFifo".c – o makefifo Execution…………..O_RDONLY|O_NONBLOCK).h> int main() { int fd..h> # include <sys/stat.."Hello world". char buff[100].*/ fd=open(". /*creating write process */ fd=open(". /*creating reader process. write(fd..c */ # include <stdio./MyFifo". RNEC page: 10 . while(read(fd.sizeof(buff))>0) printf("%s".S_IFIFO|S_IRWXU|S_IRWXG|S_IRWXO))<0) perror("\nmkfifo error. $ makefifo */ NP Lab Manual ./MyFifo".buff.buff). close(fd).12).").h> # include <sys/types..

c -o makefifo [student@localhost ~/khan]$ .c [student@localhost ~/khan]$ cc makefifo.Output: [student@localhost ~/khan]$ vi makefifo. RNEC page: 11 ./makefifo [student@localhost ~/khan]$ .: File exists NP Lab Manual ./makefifo mkfifo error...

h> # include <string.char*argv[]) { //message structure FILE*f.S. struct message msg_obj1={100.msg_data[i++]=ch."). RNEC page: 12 . int key=1234. int msg_id. //writing to msg_data } NP Lab Manual ."r"))==NULL) perror("\nUnable to open file for reading.h> # include <sys/stat.h> # include <sys/types.c */ # include <stdio. //function to put file to message Q if((f=fopen(argv[1].y..h> # include <sys/ipc..h> struct message { long msg_type. int main(int arc. int x.i=0. char ch. char msg_data[1024]. }. else { while((ch=getc(f))!=EOF) { msg_obj1.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> # include <sys/msg.E WEEK 3: Year : Semester: 2010 First Aim: Implement file transfer using Message Queue form of IPC /* file msgsendQ."I"}.

else printf("\nmsgid=%d".&msg_obj1.")... RNEC page: 13 .x). } /* Compiling………….strlen(msg_obj1.msg_data).msg_id).IPC_CREAT|0644))==-1) perror("\nUnable to get message id. return 0. /*writing message to the q */ if((x=msgsnd(msg_id.fclose(f). //closing file } //creating msg q id if((msg_id=msgget(key.. $msgsndQ <file name> */ NP Lab Manual .."). else printf("\nSend Msg Success : return %d".. $CC msgsndQ.c -o msgsndQ Execution………….IPC_NOWAIT)) ==-1) perror("\nUnable to send message.

c -o msgsndQ [student@localhost ~]$ ./msgsndQ pipe.Output: [student@localhost ~]$ cc msgsndQ.c msgid=0 Send Msg Success : return 0[student@localhost ~]$ NP Lab Manual . RNEC page: 14 .

char ch.char*argv[]) { FILE*f.0644))==-1) perror("\nUnable to get message id.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. char msg_data[1024]. else printf("\nmsgid=%d".h> # include <sys/ipc. int main(int argc..i=0. int msg_id.1024.S.. int x.").100."M"}.y). }.h> # include <sys/stat..h> # include <sys/types.E /* file msgrecvQ. struct message msg_obj2={100.h> # include <string.msg_id)..c */ # include <stdio.h> # include <sys/msg. //creating msg q id if((msg_id=msgget(1234.MSG_NOERROR))==-1) perror(":.msgrcv error. Year : Semester: 2010 First /* rec message from q*/ if((y=msgrcv(msg_id.&msg_obj2. RNEC page: 15 . NP Lab Manual . else printf("\nRec Bytes : %d".h> //message structure struct message { long msg_type.").y.

RNEC page: 16 .if((f=fopen(argv[1]. //closing file } return 0. $ msgrecvQ <new file name> */ NP Lab Manual ."w"))==NULL) perror("\nUnable to open file for writing.c -o msgrecvQ Execution…………..msg_obj2... $CC msgrecvQ."). else { for(i=0.i++) { putc(msg_obj2. } fclose(f). } /* Compiling………….f).msg_data[i].msg_data[i]!=0.

char line[MAXLINE].").Output: [student@localhost ~]$ cc msgrecvQ.c /* file name pipe."hello world\n". else if(pid>0) { close(fd[0])./msgrecv recvpipe.12).. } exit(0).c */ # include <stdio.h> # include <sys/types. } NP Lab Manual . } else { close(fd[1]). if((pid=fork())<0) perror("fork error..MAXLINE).h> # define MAXLINE 4096 int main() { int n. n=read(fd[0]. write(fd[1].c -o msgrecvQ [student@localhost ~]$ . if(pipe(fd)<0) perror("pipe error.. RNEC page: 17 .n)."). write(1.line.fd[2].c msgid=0 Rec Bytes : 415[student@localhost ~]$ cat recvpipe. pid_t pid.h> # include <stdlib.line.

h> #define SHMSZ 4 /* Good for integer */ #define BUF_SZ 16 #define SHM_KEY 1234 #define SEM_KEY 1235 #define CHILD_INCREMENT_COUNT 67787 #define PARENT_INCREMENT_COUNT 84823 union semun { int val. /* value for SETVAL */ struct semid_ds *buf. NP Lab Manual . SETALL */ /* Linux specific part: */ struct seminfo *__buf.h> #include <fcntl. /* array for GETALL. RNEC page: 18 .h> #include <string.h> # include <stdlib. IPC_SET */ unsigned short *array.h> #include <sys/shm.S. /*file name sem.h> #include <sys/types.h> #include <errno.h> #include <stdio.c */ #include <unistd.E WEEK 4: Year : Semester: 2010 First Aim: Write a program to create an integer variable using shared memory concept and increment the variable simultaniously two processes. /* buffer for IPC_STAT.h> #include <sys/ipc. Use semaphores to avoid race conditions.h> #include <sys/types. /* buffer for IPC_INFO */ }.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> #include <sys/sem.h> #include <sys/stat.

*/ if ((shmid = shmget(SHM_KEY. } /* * Initialize the semaphore to value 1. } if ((semid = semget(SEM_KEY. int *child_shm.& semaphore. 0.val = 1.main() { int shmid. arg) < 0) { perror("semctl"). int semid. 1. exit(1). key_t key. So only one is allowed in critical section. if (semctl(semid. exit(1). */ arg. *parent_shm. * initialize the shm to 0. struct sembuf operations[1]. union semun arg. IPC_CREAT | 0666)) < 0) { perror("shmget"). /* Create the shared segment. SETVAL. int status. int pid. RNEC page: 19 . int i. exit(1). } NP Lab Manual . SHMSZ. The idea is multiple processes * do semop() of -1. IPC_CREAT | 0666)) < 0) { perror("semget").

/* * create a child process. } /* * Child process attaches to shm. only one * process can do -1. Since the initial value of semaphore is 1. After semop(). NULL. */ if (pid == 0) { if ((child_shm = shmat(shmid.if ((parent_shm = shmat(shmid. They both attach to the * shared memory and use the semphore to increment the value in the shm. Then again use the semop to set the sem value to 1. */ if ((pid = fork()) < 0) { printf("Child Process Creation Error:%d\n". RNEC page: 20 . It fill operations to block till * it gets -1. The other process will see the value as 0 and * block till it sees sem value as 1. Later similar thing is * done for parent process also. so * that other process gets the chance to run. return. 0)) == (int *)-1) { perror("child shmat"). 0)) == (int *)-1) { perror("parent shmat"). } NP Lab Manual . The above opened shm & sem fds get * copied to child process as a result of fork(). exit(1). increment the shm * integer by 1. NULL. exit(1). } *parent_shm = 0. errno). * Repeat the above for a defined number of times.

1) < 0) { perror("child semop"). if (i%1000 == 0) { usleep(1). RNEC page: 21 . 1) < 0) { perror("child semop"). exit(1).sem_flg = 0.sem_num = 0. operations[0].sem_op = -1.sem_flg = 0. i++) { operations[0]. i < PARENT_INCREMENT_COUNT. if (semop(semid. } } } if (pid != 0) { for (i = 0. operations[0].sem_num = 0. exit(1). operations[0]. } *child_shm = *child_shm + 1.sem_op = 1. operations. // sleep 1 us to increase window of critical section } operations[0]. operations[0].sem_num = 0. i < CHILD_INCREMENT_COUNT. NP Lab Manual .for (i = 0. operations[0].sem_op = -1.sem_flg = 0. if (semop(semid. operations[0]. i++) { operations[0]. operations.

NP Lab Manual . */ printf("Child Incremented %d times. } *parent_shm = *parent_shm + 1. SHM Value %d \n". operations[0]. } } // wait for child to complete wait(&status). operations[0].sem_num = 0.sem_op = 1.sem_flg = 0. exit(1).PARENT_INCREMENT_COUNT.if (semop(semid. 1) < 0) { perror("parent semop"). if (semop(semid. check the * consistency of the shm memory. operations. 1) < 0) { perror("parent semop"). // sleep 1 us to increase window of critical section } operations[0]. Parent %d times. RNEC page: 22 .CHILD_INCREMENT_COUNT. operations. if (i%1500 == 0) { usleep(1). *parent_shm). exit(1). /* * now that parent and child are done incrementing.

} else { printf("BUG .c -o sema Execution………….Total of Parent & Child DOESNT match SHM value\n"). $ sema */ NP Lab Manual . $CC sem. } } exit(0).if (*parent_shm == (CHILD_INCREMENT_COUNT + PARENT_INCREMENT_COUNT)) { printf("Total of Parent & Child matches SHM value\n").. } /* Compiling…………. RNEC page: 23 .

Output: [student@localhost ~]$ cc sem.c -o sema [student@localhost ~]$ ./sema Child Incremented 67787 times, Parent 84823 times. SHM Value 152610 Total of Parent & Child matches SHM value

NP Lab Manual , RNEC

page: 24

Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.S.E WEEK 5:

Year : Semester:

2010

First

AIM: Design TCP iterative Client and server application to reverse the given input sentence /*tcp_strrev_ser.c*/

#include "unp.h" void str_echo(int sockfd) { long arg1, arg2; int x,y; ssize_t n; char line[MAXLINE]; char swp; for ( ; ; ) { if ( (n = Readline(sockfd, line, MAXLINE)) == 0) return;/* connection closed by other end */ n = strlen(line); /*strrev(line);*/ for(x=0,y=n-1;x<n/2;x++,y--) { swp=line[x]; line[x]=line[y]; line[y]=swp; } printf("\nReq From Client : %s",line); Writen(sockfd, line, n); } } int main(int argc, char **argv) { int listenfd, connfd; pid_t childpid;
NP Lab Manual , RNEC

page: 25

socklen_t clilen; 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, (SA *) &servaddr, sizeof(servaddr)); Listen(listenfd, LISTENQ); printf("Server Running on Port %d\n", SERV_PORT); for ( ; ; ) { clilen = sizeof(cliaddr); connfd = Accept(listenfd, (SA *) &cliaddr, &clilen); if ( (childpid = Fork()) == 0) { /* child process */ Close(listenfd); /* close listening socket */ str_echo(connfd); /* process the request */ exit(0); } Close(connfd); /* parent closes connected socket */ } } /* Compiling…………. $CC tcp_strrev_ser.c wrapsock.c -o tcp_strrev_ser Execution………….. $tcp_strrev_ser */

NP Lab Manual , RNEC

page: 26

/ tcp_strrev_ser Server Running on Port 9877 Req From Client : iah Req From Client : eyb Req From Client : Suspended NP Lab Manual .Output: [student@localhost ~]$ cc tcp_strrev_ser.c wrapsock.c -o tcp_strrev_ser [student@localhost ~]$ . RNEC page: 27 .

0).Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. argv[1].S. char **argv) { int sockfd. strlen(sendline)). bzero(&servaddr. stdout). sizeof(servaddr)). int sockfd) { char sendline[MAXLINE]. recvline.sin_addr). Inet_pton(AF_INET.c -o tcp_strrev_clnt Execution…………. if (argc != 2) err_quit("usage: tcpcli <IPaddress>"). sizeof(servaddr)). &servaddr.sin_family = AF_INET.c wrapsock. while (Fgets(sendline. } } int main(int argc. if (Readline(sockfd. Connect(sockfd.E /* tcp_strrev_clnt.sin_port = htons(SERV_PORT). str_cli(stdin. MAXLINE. $CC tcp_strrev_clnt. servaddr.h" Year : Semester: 2010 First void str_cli(FILE *fp. struct sockaddr_in servaddr. SOCK_STREAM. RNEC page: 28 . sockfd = Socket(AF_INET.c */ #include "unp. $tcp_strrev_clnt <IP Address> */ NP Lab Manual . } /* Compiling…………. fp) != NULL) { Writen(sockfd. (SA *) &servaddr. servaddr.. sendline. sockfd). /* do it all */ exit(0). Fputs(recvline. MAXLINE) == 0) err_quit("str_cli: server terminated prematurely"). recvline[MAXLINE].

RNEC page: 29 ./ tcp_strrev_clnt 169.254.Output: [student@localhost ~]$ .17.41 hai bye NP Lab Manual ./ tcp_strrev_clnt.c wrapsock.c –o tcp_strrev_clnt [student@localhost ~]$ .

n=i. char **argv) { int listenfd.. f=fopen(“myfile”.c */ #include "unp. fclose(f). line. arg2. SOCK_STREAM.. } } int main(int argc. /* connection closed by other end */ n = strlen(line). ssize_t n. printf("\nReq From Client for file : %s". for ( .Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. } line[i]=0. servaddr. struct sockaddr_in cliaddr. char line[MAXLINE]."r").E WEEK 6: Year : Semester: 2010 First AIM: Design TCP client and server application to transfer file /* tcp_fil_ser.S.. pid_t childpid. while((ch=getc(f))!=EOF) { line[i++]=ch. printf("\n. .line). FILE*f. int i=0.fname). RNEC page: 30 ... char ch..%s". ) { if ( (n = Readline(sockfd. Writen(sockfd.h" void str_echo(int sockfd) { long arg1. MAXLINE)) == 0) return. listenfd = Socket(AF_INET. n). NP Lab Manual . socklen_t clilen. line. 0). connfd. char fname[100].

s_addr = htonl(INADDR_ANY). RNEC page: 31 . servaddr. (SA *) &servaddr.c wrapsock. sizeof(servaddr)).sin_addr. if ( (childpid = Fork()) == 0) { /* child process */ Close(listenfd). $ tcpfileser */ NP Lab Manual . ) { clilen = sizeof(cliaddr).sin_family = AF_INET. servaddr. sizeof(servaddr)). /* process the request */ exit(0). printf("Server Running on Port %d\n". for ( . connfd = Accept(listenfd. LISTENQ). (SA *) &cliaddr. /* close listening socket */ str_echo(connfd). servaddr. . &clilen). SERV_PORT). /* parent closes connected socket */ } } /* Compiling…………. $CC tcp_file_ser. } Close(connfd). Listen(listenfd.sin_port = htons(SERV_PORT).c -o tcpfileser Execution…………. Bind(listenfd.bzero(&servaddr..

/ tcpfileser Server Running on Port 9877 NP Lab Manual . RNEC page: 32 .c –o tcpfileser [student@localhost ~]$ ./ tcp_file_ser.c wrapsock.Output: [student@localhost ~]$ .

Inet_pton(AF_INET. recvline[MAXLINE]. MAXLINE. Fputs(recvline. recvline.sin_addr).. bzero(&servaddr.c*/ #include "unp. char **argv) { int sockfd.c -o tcpfileclnt Execution…………. sockfd). str_cli(stdin. Connect(sockfd. strlen(sendline)). int sockfd) { char sendline[MAXLINE]. &servaddr. if (Readline(sockfd. MAXLINE) == 0) err_quit("str_cli: server terminated prematurely"). sendline.h" Year : Semester: 2010 First void str_cli(FILE *fp. stdout). SOCK_STREAM. 0). if (argc != 2) err_quit("usage: tcpcli <IPaddress>"). struct sockaddr_in servaddr. } /* Compiling…………. $ tcpfileclnt <IP Address> */ NP Lab Manual . sockfd = Socket(AF_INET. servaddr.c wrapsock.sin_family = AF_INET. $CC tcp_file_clnt. argv[1]. sizeof(servaddr)). (SA *) &servaddr.S.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. } } int main(int argc. servaddr. sizeof(servaddr)). fp) != NULL) { Writen(sockfd.sin_port = htons(SERV_PORT). RNEC page: 33 . /* do it all */ exit(0). while (Fgets(sendline.E /* tcp_file_clnt.

0.Output: [student@localhost ~]$ .c –o tcpfileclnt [student@localhost ~]$ .1 Hai printing from myfile NP Lab Manual .0./ tcpfileclnt 127./ tcp_file_clnt.c wrapsock. RNEC page: 34 .

ssize_t n. struct sockaddr_in cliaddr. SOCK_STREAM.S. line. ) { if ( (n = Readline(sockfd. connfd. /* converting into upper case */ for(i=0.line). } } line[i]=0. /* null */ Writen(sockfd. NP Lab Manual . } } int main(int argc. arg2. 0). pid_t childpid.i<n. n).h" void str_echo(int sockfd) { long arg1. printf("\nReq From Client : %s". /* connection closed by other end */ n = strlen(line).c */ #include "unp. RNEC page: 35 . line. socklen_t clilen.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. char **argv) { int listenfd. for ( . MAXLINE)) == 0) return. .E WEEK 7: Year : Semester: 2010 First AIM: Design a TCP concurrent server to echo given text into upper case using multiplexing system call “select” /* tcp_str_ser. servaddr. listenfd = Socket(AF_INET. char line[MAXLINE].i++) { if(line[i]>=97 && line[i]<=122) { line[i]-=32.

for ( . /* parent closes connected socket */ } } /* Compiling…………. RNEC page: 36 . Bind(listenfd.. servaddr. SERV_PORT). if ( (childpid = Fork()) == 0) { /* child process */ Close(listenfd). /* process the request */ exit(0). (SA *) &cliaddr.bzero(&servaddr. printf("Server Running on Port %d\n". &clilen).sin_family = AF_INET. connfd = Accept(listenfd. Listen(listenfd. } Close(connfd). sizeof(servaddr)).sin_addr. servaddr. (SA *) &servaddr. servaddr. LISTENQ). $CC tcp_str_ser. /* close listening socket */ str_echo(connfd). .c wrapsock. $ tcpstrser */ NP Lab Manual .s_addr = htonl(INADDR_ANY).c -o tcpstrser Execution………….sin_port = htons(SERV_PORT). sizeof(servaddr)). ) { clilen = sizeof(cliaddr).

Output: [student@localhost ~]$ cc tcpstrser./tcpstrser Server Running on Port 9877 Req From Client : khan Req From Client : ram Req From Client : karthik NP Lab Manual . RNEC page: 37 .c wrapsock.c -o tcpstrser [student@localhost ~]$ .

sin_port = htons(SERV_PORT).c -o tcpstrclnt Execution…………. sizeof(servaddr)). while (Fgets(sendline. if (Readline(sockfd. int sockfd) { char sendline[MAXLINE]. Inet_pton(AF_INET.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. sockfd = Socket(AF_INET. &servaddr. (SA *) &servaddr. stdout). MAXLINE) == 0) err_quit("str_cli: server terminated prematurely"). MAXLINE. } } int main(int argc. recvline.c wrapsock. 0).S. fp) != NULL) { Writen(sockfd. recvline[MAXLINE]. sendline. str_cli(stdin. if (argc != 2) err_quit("usage: tcpcli <IPaddress>"). strlen(sendline)). char **argv) { int sockfd. argv[1]. SOCK_STREAM. sockfd). } /* Compiling………….c */ #include "unp.sin_addr). servaddr. $CC tcp_str_clnt. Fputs(recvline. sizeof(servaddr)). bzero(&servaddr.sin_family = AF_INET.h" Year : Semester: 2010 First void str_cli(FILE *fp.. Connect(sockfd. $ tcpstrclnt <IP Address> */ NP Lab Manual . RNEC page: 38 . servaddr. struct sockaddr_in servaddr.E /* tcp_strrev_clnt. /* do it all */ exit(0).

c wrapsock.Output: [student@localhost ~]$ cc tcpstrclnt.17.254./tcpstrclnt 169.41 khan KHAN ram RAM karthik KARTHIK NP Lab Manual . RNEC page: 39 .c -o tcpstrclnt [student@localhost ~]$ .

y. SOCK_DGRAM.S. int sd. rc. char swp. if(sd<0) { printf("%s: cannot open socket \n".h> #include <netdb.h> #include <stdio. cliLen. 0). } /* bind local server port */ servAddr.h> /* memset() */ #define LOCAL_SERVER_PORT 1500 #define MAX_MSG 100 int main(int argc.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. exit(1). RNEC page: 40 . char msg[MAX_MSG]. /* socket creation */ sd=socket(AF_INET.h> /* close() */ #include <string. n.h> #include <unistd.h> #include <arpa/inet. servAddr.h> #include <sys/types. flags.c */ /* UDP echo client/server with select() (timeout option).c */ #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.E WEEK 8: Year : Semester: 2010 First Aim: Design UDP client and server application to reverse the given input sentence /* udp_strrev_ser. struct sockaddr_in cliAddr.x. See udpClient.sin_family = AF_INET. char *argv[]) { int l.argv[0]). NP Lab Manual .

sizeof(servAddr)). if(n<0) { printf("%s: cannot receive data \n".LOCAL_SERVER_PORT).x<l/2.sin_port = htons(LOCAL_SERVER_PORT). msg[y]=swp. if(rc<0) { printf("%s: cannot bind port number %d \n".y--) { swp=msg[x]. argv[0].sin_addr. msg[x]=msg[y].s_addr = htonl(INADDR_ANY). NP Lab Manual . flags. (struct sockaddr *) &servAddr. } /*reversing string */ l=strlen(msg). } printf("%s: waiting for data on port UDP %u\n". } /* print received message */ printf("%s: from %s:UDP%u : %s \n". exit(1).y=l-1. LOCAL_SERVER_PORT). rc = bind (sd. argv[0]. /* receive message */ cliLen = sizeof(cliAddr).servAddr.(struct sockaddr *)&cliAddr. msg. n = recvfrom(sd. servAddr.MAX_MSG).x++. RNEC page: 41 . for(x=0. continue.&cliLen). MAX_MSG. flags = 0.0x0.argv[0]). /* server infinite loop */ while(1) { /* init buffer */ memset(msg.

sin_port).(struct sockaddr *)&cliAddr. RNEC page: 42 .inet_ntoa(cliAddr. sendto(sd. sleep(1). } /* Compiling………….c wrapsock.c -o udpstrrevser Execution…………..argv[0].n. ntohs(cliAddr. }/* end of server infinite loop */ return 0.sin_addr).cliLen).flags.msg). $CC udp_strrev_ser. $udpstrrevser */ NP Lab Manual .msg.

41:UDP32782 : woh .41:UDP32782 : u NP Lab Manual .41:UDP32782 : era .17.Output: [student@localhost ~]$ cc udp_strrev_ser.17.17.c wrapsock./ udpstrrevser: from 169.254./ udpstrrevser: from 169.41:UDP32782 : iah .c -o udpstrrrevser [student@localhost ~]$ .254. RNEC page: 43 ./ udpstrrevser: from 169.254.17./ udpstrrevser: waiting for data on port UDP 1500 ./udpstrrevser .254./ udpstrrevser: from 169.

h> /* for exit() */ #include <sys/types.0.c */ #include <stdlib.&socketReadSet.h> /* memset() */ #include <sys/time.h> #include <string.tv_sec = timeOut / 1000.h> #include <stdio.int * error.h> #include <netinet/in. return 0. tv.h> #include <unistd. FD_SET(sd.0.tv_usec = 0. if (timeOut) { tv.h> #include <netdb. } // if NP Lab Manual .h> /* select() */ Year : Semester: 2010 First #define REMOTE_SERVER_PORT 1500 #define MAX_MSG 100 #define SOCKET_ERROR -1 int isReadable(int sd. } // if if (select(sd+1.tv_usec = (timeOut % 1000) * 1000.E /*udp_strrev_clnt. RNEC page: 44 .h> #include <sys/socket. tv. } else { tv.&tv) == SOCKET_ERROR) { *error = 1.int timeOut) { // milliseconds fd_set socketReadSet.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.tv_sec = 0. struct timeval tv.&socketReadSet).h> #include <arpa/inet.S. FD_ZERO(&socketReadSet).

remoteServAddr. timeOut.&socketReadSet) != 0. exit(1). echoLen. exit(1).. } printf("%s: sending data to '%s' (IP : %s) \n". h>h_length). argv[0]. } NP Lab Manual . echoServAddr. flags. exit(1). if(h==NULL) { printf("%s: unknown host '%s' \n".. /* check command line args */ if(argc<3) { printf("usage : %s <server> <data1> .sin_port = htons(REMOTE_SERVER_PORT).*error = 0. rc. inet_ntoa(*(struct in_addr *)h->h_addr_list[0])). error. RNEC page: 45 . <dataN> \n". char msg[MAX_MSG]. /* socket creation */ sd = socket(AF_INET. char *argv[]) { int sd. h->h_name.sin_family = h->h_addrtype. if(sd<0) { printf("%s: cannot open socket \n".0). struct sockaddr_in cliAddr.s_addr. n. memcpy((char *) &remoteServAddr. remoteServAddr. return FD_ISSET(sd.SOCK_DGRAM.argv[0]). argv[1]).sin_addr.h->h_addr_list[0]. i. remoteServAddr. argv[0]. } /* isReadable */ int main(int argc. } /* get server IP address (no check if input is IP address or DNS name */ h = gethostbyname(argv[1]). struct hostent *h. argv[0]).

MAX_MSG). timeOut = 100. while (!isReadable(sd.&echoLen).sin_addr. flags. n = recvfrom(sd.&error. argv[0]). exit(1).sizeof(remoteServAddr)).i++) { rc = sendto(sd.sin_family = AF_INET. } flags = 0. strlen(argv[i])+1. cliAddr. (struct sockaddr *) &cliAddr. sizeof(cliAddr)). cliAddr.").(struct sockaddr *) &echoServAddr.argv[0]. if(rc<0) { printf("%s: cannot send data %d \n".timeOut)) printf(". // ms /* send data */ for(i=2.i<argc. flags. msg. argv[i]. RNEC page: 46 . /* receive echoed message */ echoLen = sizeof(echoServAddr). (struct sockaddr *) &remoteServAddr. rc = bind(sd.0x0. exit(1).s_addr = htonl(INADDR_ANY). } /* BEGIN jcs 3/30/05 */ /* init buffer */ memset(msg.i-1)./* bind any port */ cliAddr. MAX_MSG. close(sd). NP Lab Manual . if(rc<0) { printf("%s: cannot bind port\n".sin_port = htons(0). printf("\n").

sin_port). $ cc udp_strrev_clnt. $ udpstrrevclnt <IP Address> data */ NP Lab Manual . } return 1. RNEC page: 47 .if(n<0) { printf("%s: cannot receive data \n". } /* Compiling…………. continue.ntohs(echoServAddr.argv[0]). } /* print received message */ printf("%s: echo from %s:UDP%u : %s \n".argv[0].m sg)..inet_ntoa(echoServAddr.sin_addr).c -o udpstrrevclnt Execution………….c wrapsock.

17.41 hai how are u ..254........254.c wrapsock..41' (IP : 169....17.Output: [student@localhost ~]$ cc udp_strrev_clnt. .17.c -o udpstrrevclnt [student@localhost ~]$ .41:UDP1500 : u NP Lab Manual ../ udpstrrevclnt: sending data to '169... ./ udpstrrevclnt 169.... ..../udpstrrevclnt: echo from 169.254...17....41:UDP1500 : woh .41) ..17.254.17../ udpstrrevclnt: echo from 169.41:UDP1500 : iah ..41:UDP1500 : era ./ udpstrrevclnt: echo from 169...254..254...17... ./ udpstrrevclnt: echo from 169.254. RNEC page: 48 .

c */ #include <stdlib.ch. /* socket creation */ sd=socket(AF_INET. n. flags.h> #include <sys/socket. char fname[100]. SOCK_DGRAM.h> #include <unistd.h> /* close() */ #include <string. char *argv[]) { FILE*f.sin_addr. if(sd<0) { printf("%s: cannot open socket \n".S. } /* bind local server port */ servAddr. servAddr.sin_port = htons(LOCAL_SERVER_PORT). exit(1). 0). servAddr.h> #include <arpa/inet. struct sockaddr_in cliAddr. int i=0.h> #include <sys/types. char msg[MAX_MSG]. cliLen. rc. servAddr.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.E WEEK 9: Aim: Design UDP client server to transfer a file /* server program */ /* udp_file_ser.argv[0]).h> #include <netinet/in. int sd.h> /* memset() */ #define LOCAL_SERVER_PORT 1500 #define MAX_MSG 3000 int main(int argc.h> #include <netdb. RNEC Year : Semester: 2010 First page: 49 .h> #include <stdio.s_addr = htonl(INADDR_ANY).sin_family = AF_INET. NP Lab Manual .

. argv[0]. (struct sockaddr *) &servAddr. n=i.LOCAL_SERVER_PORT). /* receive message */ cliLen = sizeof(cliAddr)."). continue. if(n<0) { printf("%s: cannot receive data \n". } msg[i]='\0'. argv[0]. //reading data to msg while((ch=getc(f))!=EOF) { msg[i++]=ch. flags. flags = 0.MAX_MSG). MAX_MSG. //closing stream /* print received message */ NP Lab Manual . RNEC page: 50 . LOCAL_SERVER_PORT). } printf("%s: waiting for data on port UDP %u\n". exit(1). i=0. /* server infinite loop */ while(1) { /* init buffer */ memset(msg.argv[0]).(struct sockaddr *) &cliAddr.sizeof(servAddr)). &cliLen). msg. } /*reading file contents */ strcpy(fname. if(rc<0) { printf("%s: cannot bind port number %d \n". fclose(f). n = recvfrom(sd..msg). if((f=fopen(fname."r"))==NULL) perror("\nFile not found.rc = bind (sd.0x0.

ntohs(cliAddr.msg).(struct sockaddr *)&cliAddr.flags..msg.c wrapsock. RNEC page: 51 . $ cc udp_file_ser.c -o udp_file_ser Execution…………. } /* Compiling………….printf("%s: from %s:UDP%u : %s \n" . argv[0].sin_port). inet_ntoa(cliAddr.sin_addr). $ udp_file_ser */ NP Lab Manual . }/* end of server infinite loop */ return 0.n. sendto(sd.cliLen). sleep(1).

c wrapsock.buff.c -o udp_file_ser [student@localhost ~]$ .argv[1]).")./ udp_file_ser: from 169. } exit(0).h> #include<stdlib.char*argv[]) { int fd.MAXLINE))>0) { write(1. exit(0)..h> #include<fcntl.Output: [student@localhost ~]$ cc udp_file_ser.41:UDP32782 : #include<stdio. exit(0)./udptranser: waiting for data on port UDP 1500 . char buff[2000].17.n.h> #define MAXLINE 4096 int main(int argc.254. } else printf("\n %s file is opened". while((n=read(fd. } if((fd=open(argv[1]. } NP Lab Manual .argv[1]). RNEC page: 52 .buff.n)..O_RDONLY))<0) { printf("\n unable to open file%s"./ udp_file_ser . if(argc=2) { printf("\n wrong arg.h> #include<sys/types.

tv.h> /* memset() */ #include <sys/time.h> #include <stdio. FD_SET(sd.h> /* for exit() */ #include <sys/types.h> #include <unistd.h> #include <sys/socket.c */ #include <stdlib.&socketReadSet.S. } // if if (select(sd+1.tv_sec = timeOut / 1000.tv_usec = (timeOut % 1000) * 1000.int * error.tv_usec = 0.tv_sec = 0.h> #include <arpa/inet. return 0.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> /* select() */ #define REMOTE_SERVER_PORT 1500 #define MAX_MSG 3000 #define SOCKET_ERROR -1 Year : Semester: 2010 First int isReadable(int sd. if (timeOut) { tv. tv. RNEC page: 53 .0.0.&tv) == SOCKET_ERROR) { *error = 1. } // if NP Lab Manual .h> #include <netinet/in.h> #include <string. } else { tv.&socketReadSet). FD_ZERO(&socketReadSet). struct timeval tv.h> #include <netdb.int timeOut) { // milliseconds fd_set socketReadSet.E /* udp_file_clnt.

char msg[MAX_MSG]. exit(1). char *argv[]) { int sd. if(h==NULL) { printf("%s: unknown host '%s' \n". if(sd<0) { printf("%s: cannot open socket \n". RNEC page: 54 . h->h_name. } printf("%s: sending data to '%s' (IP : %s) \n". remoteServAddr. n. struct hostent *h.sin_family = h->h_addrtype.s_addr.SOCK_DGRAM. return FD_ISSET(sd. argv[1]). } /* isReadable */ /* END jcs 3/30/05 */ int main(int argc. } /* bind any port */ NP Lab Manual .h->h_addr_list[0].argv[0]). exit(1). } /* get server IP address (no check if input is IP address or DNS name */ h = gethostbyname(argv[1]). inet_ntoa(*(struct in_addr *)h->h_addr_list[0])). h->h_length). exit(1). memcpy((char *) &remoteServAddr.sin_addr.. rc.*error = 0. echoLen. i. <dataN> \n". echoServAddr. /* check command line args */ if(argc<3) { printf("usage : %s <server> <data1> . struct sockaddr_in cliAddr. error. timeOut. remoteServAddr.0). /* socket creation */ sd = socket(AF_INET. flags..sin_port = htons(REMOTE_SERVER_PORT). argv[0]. remoteServAddr.&socketReadSet) != 0. argv[0]. argv[0]).

cliAddr.i<argc.&error.i++) { rc = sendto(sd. /* receive echoed message */ echoLen = sizeof(echoServAddr). // ms /* send data */ for(i=2.i-1).argv[0]). } flags = 0. cliAddr. continue.").sin_addr. if(n<0) { printf("%s: cannot receive data \n". } /* init buffer */ memset(msg.(struct sockaddr *) &echoServAddr. rc = bind(sd. exit(1). n = recvfrom(sd. printf("\n"). (struct sockaddr *) &cliAddr. flags.sin_family = AF_INET.s_addr = htonl(INADDR_ANY). flags. msg. MAX_MSG.timeOut)) printf(". RNEC page: 55 . exit(1). strlen(argv[i])+1. argv[i].argv[0]. sizeof(cliAddr)). } NP Lab Manual . (struct sockaddr *) &remoteServAddr. while (!isReadable(sd. argv[0]).sin_port = htons(0). close(sd). if(rc<0) { printf("%s: cannot send data %d \n". cliAddr. sizeof(remoteServAddr)).0x0. if(rc<0) { printf("%s: cannot bind port\n".MAX_MSG). timeOut = 100. &echoLen).

RNEC page: 56 .sin_addr)./* print received message */ printf("%s: echo from %s:UDP%u : %s \n".c -o udp_file_clnt Execution…………. $CC cc udp_file_clnt. } return 1.ntohs(echoServAddr.sin_port). $ udp_file_clnt <IP Address> <File Name> */ NP Lab Manual . } /* Compiling………….m sg)..argv[0].c wrapsock.inet_ntoa(echoServAddr.

c wrapsock..").17.41 io..buff.c -o udp_file_clnt [student@localhost ~]$ .O_RDONLY))<0) { printf("\n unable to open file%s". RNEC page: 57 . if(argc=2) { printf("\n wrong arg. exit(0).17./ udp_file_clnt 169. while((n=read(fd.argv[1]).. exit(0). } if((fd=open(argv[1].argv[1]). .254.h> #include<fcntl..17.254.41:UDP1500 : #include<stdio.h> #define MAXLINE 4096 int main(int argc. char buff[2000]..buff.MAXLINE))>0) { write(1./ udp_file_clnt i: sending data to '169.41' (IP : 169...254. } exit(0)..Output: [student@localhost ~]$ cc udp_file_clnt.254.char*argv[]) { int fd./ udp_file_clnt: echo from 169. } else printf("\n %s file is opened".n.h> #include<sys/types.41) .n)...c . } NP Lab Manual .17.h> #include<stdlib..

l. n.h> #include <netdb. servAddr.sin_family = AF_INET.E WEEK 10: Year : Semester: 2010 First AIM: Design a UDP poll client server application to multiplex TCP and UDP requests for converting a given text in to upper case /* tcp_str_ser. RNEC page: 58 . servAddr.sin_addr. rc. (struct sockaddr *) &servAddr.sin_port = htons(LOCAL_SERVER_PORT).h> /* close() */ #include <string. flags.c */ #include <stdlib. char msg[MAX_MSG]. struct sockaddr_in cliAddr. exit(1).s_addr = htonl(INADDR_ANY). } /* bind local server port */ servAddr.h> #include <sys/types.x.h> #include <sys/socket. 0).h> #include <stdio. rc = bind (sd. /* socket creation */ sd=socket(AF_INET.h> #include <unistd. if(sd<0) { printf("%s: cannot open socket \n". servAddr.argv[0]).sizeof(servAddr)). char *argv[]) { int sd. cliLen. SOCK_DGRAM.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> /* memset() */ #define LOCAL_SERVER_PORT 1500 #define MAX_MSG 100 int main(int argc.h> #include <arpa/inet. NP Lab Manual .h> #include <netinet/in.S.

for(x=0.MAX_MSG).argv[0]). ntohs(cliAddr. &cliLen).if(rc<0) { printf("%s: cannot bind port number %d \n".sin_port). } } /* print received message */ printf("%s: from %s:UDP%u : %s \n". argv[0]. exit(1). msg. } l=strlen(msg). LOCAL_SERVER_PORT). } printf("%s: waiting for data on port UDP %u\n". /* receive message */ cliLen = sizeof(cliAddr).msg). MAX_MSG.0x0. /* BEGIN jcs 3/30/05 */ NP Lab Manual . argv[0]. /* BEGIN jcs 3/30/05 */ flags = 0. n = recvfrom(sd.LOCAL_SERVER_PORT).x++) { if(msg[x]>=97&&msg[x]<=122) { msg[x]-=32. continue.x<l. argv[0]. (struct sockaddr *) &cliAddr. if(n<0) { printf("%s: cannot receive data \n".sin_addr). flags. RNEC page: 59 . /* END jcs 3/30/05 */ /* server infinite loop */ while(1) { /* init buffer */ memset(msg.inet_ntoa(cliAddr.

n.c -o udpstrser Execution………….flags. $udpstrser */ NP Lab Manual .c wrapsock.sleep(1). } /* Compiling………….(struct sockaddr *)&cliAddr.cliLen).msg. RNEC page: 60 . $CC udp_str_ser.. sendto(sd. /* END jcs 3/30/05 */ } /* end of server infinite loop */ return 0.

0.1 : UDP32768: HAI udpstrser : from 127.Output: [student@localhost ~]$ cc udp_str_ser./udpstrser udpstrser : waiting for data on port UDP 1500 udpstrser : from 127.0.0.0. RNEC page: 61 .1 : UDP32768: YOU NP Lab Manual .1 : UDP32768: HOW udpstrser : from 127.c wrapsock.1 : UDP32768: ARE udpstrser : from 127.c -o udpstrser [student@localhost ~]$.0.0.0.0.

h> #include <string.h> #include <netdb.h> /* memset() */ #include <sys/time.h> #include <unistd.int timeOut) { // milliseconds fd_set socketReadSet.&socketReadSet).h> #include <netinet/in.int * error. FD_SET(sd. struct timeval tv. tv. FD_ZERO(&socketReadSet).h> #include <arpa/inet. } // if NP Lab Manual .h> /* for exit() */ #include <sys/types.tv_sec = timeOut / 1000. if (timeOut) { tv. tv.tv_usec = (timeOut % 1000) * 1000.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> /* select() */ #define REMOTE_SERVER_PORT 1500 #define MAX_MSG 100 #define SOCKET_ERROR -1 int isReadable(int sd.tv_sec = 0.tv_usec = 0. RNEC Year : Semester: 2010 First page: 62 .c*/ #include <stdlib.E /*udp_str_clnt.h> #include <stdio.S.h> #include <sys/socket. } else { tv.

return FD_ISSET(sd. argv[0]. } /* isReadable */ /* END jcs 3/30/05 */ int main(int argc. remoteServAddr. argv[0]). timeOut.&tv) == SOCKET_ERROR) { *error = 1. i. /* socket creation */ sd = socket(AF_INET.sin_port = htons(REMOTE_SERVER_PORT). struct sockaddr_in cliAddr.0.0. error. char *argv[]) { int sd. return 0. h->h_length).SOCK_DGRAM.&socketReadSet. char msg[MAX_MSG]. NP Lab Manual . /* check command line args */ if(argc<3) { printf("usage : %s <server> <data1> .s_addr. echoLen. memcpy((char *) &remoteServAddr. argv[0]. } printf("%s: sending data to '%s' (IP : %s) \n". <dataN> \n".0).sin_family = h->h_addrtype.&socketReadSet) != 0. remoteServAddr. flags. exit(1). remoteServAddr.. rc.if (select(sd+1. echoServAddr. struct hostent *h. h->h_name. n.. argv[1]). exit(1). if(h==NULL) { printf("%s: unknown host '%s' \n". inet_ntoa(*(struct in_addr *)h->h_addr_list[0])). RNEC page: 63 . h->h_addr_list[0].sin_addr. } // if *error = 0. } /* get server IP address (no check if input is IP address or DNS name */ h = gethostbyname(argv[1]).

i-1). /* receive echoed message */ echoLen = sizeof(echoServAddr). // ms /* END jcs 3/30/05 */ /* send data */ for(i=2. exit(1). } /* bind any port */ cliAddr. NP Lab Manual .sin_port = htons(0). cliAddr.0x0. printf("\n"). } /* BEGIN jcs 3/30/05 */ /* init buffer */ memset(msg. exit(1).timeOut)) printf(". strlen(argv[i])+1. sizeof(remoteServAddr)).MAX_MSG). n = recvfrom(sd. RNEC page: 64 . close(sd). MAX_MSG.i<argc.&error. } /* BEGIN jcs 3/30/05 */ flags = 0. flags. argv[i].s_addr = htonl(INADDR_ANY).if(sd<0) { printf("%s: cannot open socket \n". msg. exit(1).sin_addr. argv[0]). flags. rc = bind(sd. sizeof(cliAddr)).argv[0]. while (!isReadable(sd.sin_family = AF_INET. if(rc<0) { printf("%s: cannot send data %d \n".argv[0]).i++) { rc = sendto(sd. (struct sockaddr *) &remoteServAddr. cliAddr. (struct sockaddr *) &cliAddr."). if(rc<0) { printf("%s: cannot bind port\n". timeOut = 100.

continue.c -o udpstrclnt Execution…………. $CC udp_str_clnt. } /* print received message */ printf("%s: echo from %s:UDP%u : %s \n". if(n<0) { printf("%s: cannot receive data \n".argv[0])..sin_addr).(struct sockaddr *) &echoServAddr.msg). RNEC page: 65 . &echoLen). ntohs(echoServAddr. argv[0].inet_ntoa(echoServAddr. /* END jcs 3/30/05 */ } return 1. } /* Compiling…………. $udpstrclnt <IP Address> data */ NP Lab Manual .c wrapsock.sin_port).

RNEC page: 66 .1 : UDP1500 : YOU ………… NP Lab Manual .0.0.0.0.1‟ (IP:127.Output: [student@localhost ~]$ cc udp_str_clnt./udpstrclnt 127.0.c wrapsock.0.0.0.1 : UDP1500 : ARE ………… udpstrclnt : echo from 127.1 : UDP1500 : HOW ………… udpstrclnt : echo from 127.1 : UDP1500 : HAI ………… udpstrclnt : echo from 127.0.0.0.0.1 hai how are you udpstrclnt: sending data to „127.0.1) ………… udpstrclnt : echo from 127.c -o udpstrclnt [student@localhost ~]$.0.

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times