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. we should always be sure to close the end of pipe we aren't concerned with.o after all calls to close If the parent wants to receive data from the child. it should close fd0. If the parent wants to send data to the child. and the child should close fd0. and the child should close fd1. it should close fd1. On a technical note.webs.blogspot.com Ravinuthalavs. the EOF will never be returned if the unnecessary ends of the pipe are not explicitly closed.com . NP Lab Manual . Since descriptors are shared between the parent and child.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Output: [student@localhost ~]$ cc tcp_strrev_ser. 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 .c -o tcp_strrev_ser [student@localhost ~]$ .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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