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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

/* value for SETVAL */ struct semid_ds *buf.h> #include <sys/sem.c */ #include <unistd.S.h> #include <sys/ipc.h> #include <sys/stat. SETALL */ /* Linux specific part: */ struct seminfo *__buf.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.h> # include <stdlib.h> #include <string. /*file name sem. IPC_SET */ unsigned short *array.h> #include <sys/types.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> #include <errno.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.h> #include <fcntl. /* buffer for IPC_INFO */ }. RNEC page: 18 .h> #include <sys/types.h> #include <stdio.h> #include <sys/shm. Use semaphores to avoid race conditions. NP Lab Manual . /* array for GETALL. /* buffer for IPC_STAT.

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

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

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

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

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

c -o tcp_strrev_ser [student@localhost ~]$ . RNEC page: 27 .c wrapsock./ 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.

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

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

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

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

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

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

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

for ( . connfd. listenfd = Socket(AF_INET. line. printf("\nReq From Client : %s".line). char line[MAXLINE]. .i<n. ) { if ( (n = Readline(sockfd. arg2. /* connection closed by other end */ n = strlen(line). SOCK_STREAM. n). /* null */ Writen(sockfd.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. MAXLINE)) == 0) return. 0). char **argv) { int listenfd.Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C. RNEC page: 35 . ssize_t n. } } int main(int argc.i++) { if(line[i]>=97 && line[i]<=122) { line[i]-=32. socklen_t clilen. /* converting into upper case */ for(i=0.c */ #include "unp. } } line[i]=0. NP Lab Manual . struct sockaddr_in cliaddr.S. pid_t childpid.h" void str_echo(int sockfd) { long arg1. servaddr. line.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

cliLen.h> #include <sys/socket. char msg[MAX_MSG]. (struct sockaddr *) &servAddr.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 . rc.h> #include <sys/types. servAddr.c */ #include <stdlib.sizeof(servAddr)).S. NP Lab Manual . rc = bind (sd. servAddr.s_addr = htonl(INADDR_ANY).h> #include <arpa/inet. struct sockaddr_in cliAddr.sin_family = AF_INET. char *argv[]) { int sd. if(sd<0) { printf("%s: cannot open socket \n". servAddr.sin_port = htons(LOCAL_SERVER_PORT).Subject: NETWORK PROGRAMMING LAB Class : IV B-Tech C.h> #include <unistd.h> #include <netinet/in. flags.h> #include <netdb.argv[0]). 0).l.h> #include <stdio. /* socket creation */ sd=socket(AF_INET.x. exit(1).sin_addr.h> /* close() */ #include <string.h> /* memset() */ #define LOCAL_SERVER_PORT 1500 #define MAX_MSG 100 int main(int argc. } /* bind local server port */ servAddr. n. SOCK_DGRAM.

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

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

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

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

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

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

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

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

Sign up to vote on this title
UsefulNot useful