+ All Categories
Home > Documents > Np Lab Manual

Np Lab Manual

Date post: 08-Nov-2014
Category:
Upload: prajapati-chetan
View: 15 times
Download: 2 times
Share this document with a friend
Description:
lab manual
Popular Tags:
12
CSE 314 Computer Networks LAB VI Sem, BE (CS&E) JAN 2012 LAB MANUAL
Transcript
Page 1: Np Lab Manual

CSE 314 Computer Networks LAB

VI Sem, BE (CS&E)

JAN 2012

LAB MANUAL

Page 2: Np Lab Manual

CONTENTS

SL NO TITLE OF EXPERIMENT

1 Review of UNIX System Calls

2 TCP Server/Client

3 TCP ECHO Server/Client, TCP Daytime Server/Client

4 TCP Chat Server/Client, File Transfer Server

5 Applications based on Datagram sockets

6 Remote Server application using TCP

7 Synchronous I/O multiplexing

8 Develop client/server application protocol using the commands list, get, put and cd

9 Data Encapsulation, decapsulation, fragmentation

10 Review of Java connection commands like getByName , getAllByName, etc:

11 Applications based on Datagram sockets using JAVA

12 Applications based on TCP sockets using JAVA

Page 3: Np Lab Manual

LIST OF EXPERIMENTS

Programs Using UNIX and C

WEEK1

REVIEW OF UNIX SYSTEM CALLS

1. Write C programs using vi editor and execute to illustrate the use of the following UNIX system calls.Open(): opens a file in the specified modeClose():closes specified file descriptorRead():read from a fileWrite():write to a fileCreat(): create a file Fork(): creates a child processWait(): process wait for its child’s terminationExecve():executes a specified executable fileAlarm(): sending an alarm signalSignal(): to handle the signal

2. Write a program to copy one file to another using file system calls3. Write a program to create a child process to execute the above program4. Write a program to introduce an infinite loop and comes out of the loop using alarm

and signal

Page 4: Np Lab Manual

WEEK2

STREAM (TCP) SERVER/CLIENTUse the following system calls

Sockfd=socket (AF_INET, SOCK_STREAM, 0)) socket():create a stream socket

int bind(int sockfd, const struct sockaddr*myaddr, socklen_t addrlen);bind(): binding an address to the socket

int connect(int sockfd, const struct sockaddr*servaddr, socklen_t addrlen); connect(): request for connection

int listen (int sockfd, int backlog);listen():listening for connections

int accept(int sockfd,struct sock addr*cliaddr, socklen_t*addrlen);accept(): accept a connection.

ssize_t read(int fildes, void*buff, size_t nbytes);ssize_t write(int fildes, void*buff, size_t nbytes);

Send()/write():send stream of data Recv()/read():receive dataClose():close a socket

1. Write a simple client and server programs and test the data transfer between them by running them on different LINUX servers.

2. Modify the above server as concurrent server to accept several clients and serve concurrently (Hint: Use fork()).

Page 5: Np Lab Manual

WEEK3

APPLICATIONS BASED ON STREAM SOCKETS

Write programs to implement the following:1. TCP ECHO Server/Client

Hint : Server executes recv(sd,buf,len) and send(sd,buf,len)Client executes send(sd,buf,len) and recv(sd,buf,len)

2. TCP daytime Server/ClientHint: Use time(&t) and asctime(localtime(t)) at the server .

Store timing information in buffer and send to clientClient simply receives what server sends

WEEK4

APPLICATIONS BASED ON STREAM SOCKETS

1. TCP CHAT Server/ClientHint: Server and client will be in infinite loop to execute

Send() and recv() until quit is given by the user2. File Transfer Server

Hint: Client sends filename by executing send()Server reads the filename , opens the file ,reads the file

and sends the file content to the client.

Page 6: Np Lab Manual

WEEK5

DATAGRAM (UDP) SERVER/CLIENT

Use the following system callsSocket(): create a datagram socketBind():Binding an address to the socketConnect():request for connectionSendto():send datagramRecvfrom: receive datagramClose():close a socket

Ssize_t recvfrom(int sockfd , void*buff , size_t nbytes , int flags , struct sockadr*from , socklen_t*addrlen);

Ssize_t sendto(int sockfd , void*buff , size_t nbytes , int flags , const struct sockadr*to , socklen_t addrlen);

APPLICATIONS BASED ON DATAGRAM SOCKETSWrite programs to implement the following:

1. UDP iterative server/client to transfer simple messages.2. UDP ECHO Server/Client

Hint : Server executes recvfrom(sd,buf,len) and sendto(sd,buf,len)Client executes sendto(sd,buf,len) and recvfrom(sd,buf,len)

3. UDP daytime Server/ClientHint: Use time(&t) and asctime(localtime(t)) at the server .

Store timing information in buffer and send to clientClient simply receives what server sends

4. Write a program that uses socket to create a “remote math” protocol. The client sends two integers and an operator. The operations can be addition, subtraction, multiplication and division. The server performs the operation on the integers and returns the result.

WEEK6

Develop a client/server based application using TCP to execute the program at remote server.i.e. the client sends the executable file to the server, server executes the file , stores the result in a file and sends back to the client.

Page 7: Np Lab Manual

WEEK7Synchronous I/O multiplexing : use select() function

Select function#include <sys/select.h>#include<sys/time.h>int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); tell the kernel what descriptors we are interested in and how long to wait

Readset, writeset and exceptset :specify the descriptors that we want the kernel to test for reading, writing and exception condition

FD_ZERO(fd_set *fdset) /*clear all bits in fdset*/ FD_SET(int fd, fd_set *fdset) /*turn on the bit for fd in fdset*/ FD_CLR(int fd, fd_set *fdset) /*turn off the bit for fd in fdset*/ Int FD_ISSET (int fd, fd_set *fdset) /*is the bit for fdset*/

I/O Multiplexing/*test if either of the two socket descriptors are ready for read*/int checkSocketReadyForRead (int sockfd1, int sockfd2){fd_set read; int maxfd;struct timeval wait_time;wait_time.tv_sec=1; wait_time.tv_usec=500;FD_ZERO(&read);FD_SET(sockfd1,&read); FD_SET(sockfd2,&read);maxfd=(sockfd1> sockfd2?sockfd1:sockfd2)+1;

Example of using the select callwhile (select(maxfd,&read,(fd_set*)0, (fd_set*)0,&wait_time)==-1){if (errno=EINTR){/*interrupted*/wait_time.tv_sec=1; wait_time.tv_usec=500;continue;/*do it again*/} else{ return -1; /*error occurred*/ }}/*end while*/if (FD_ISSET(sockfd1,&read)) return 1; /*sockfd1 ready*/else if (FD_ISSET(sockfd2,&read)) return 2; /*sockfd2 ready*/else return -2;} /*end of function*/

Exercise:1. Write a program to illustrate the use of ‘select()’ system call2. Develop a multi user chat server using synchronous I/O multiplexing

Page 8: Np Lab Manual

WEEK 8

Develop a client/server application protocol to support the following commands.1. List : display the list of files at server2. Get: download the specified file from server3. Put: upload the file to server4. Cd: change directory at server

WEEK 9

Write C programs to simulate the following:1. Testing the class of a given IP address2. Data encapsulation and decapsulation3. Fragmentation and reassembling of datagrams4. Checksum calculation and verification.

Programs using JAVA on windows

WEEK 10

1. Illustrate the use of getByName(), getAllByName(), getLocalHost() ,getHostName(),

getHostAddress().

2. Write a program to test the class of a given IP address.

WEEK 11

Write programs to implement following

1. UDP iterative server/client to transfer simple messages.2. UDP ECHO server/client

[Hint: Server executes recvfrom(sd,buf,len) and sendto(sd,buff,len)Client executes sendto(sd,buf,len) and recvfrom(sd,buff,len) in that order.

3. UDP daytime server/client.[Hint: Use time(&t) and asctime(localtime(t)) at the server. Store timing information in the buffer and send to client. Client simply receives what server sends.

WEEK 12

Write programs to implement following

Page 9: Np Lab Manual

1. TCP ECHO server/client[Hint: Server executes recv(sd,buf,len) and sendto(sd,buff,len)Client executes sendto(sd,buf,len) and recvfrom(sd,buff,len) in that order.

2. TCP daytime server/client.[Hint: Use time(&t) and asctime(localtime(t)) at the server. Store timing information in the buffer and send to client. Client simply receives what server sends

REFERENCES

1. UNIX NETWORK PROGRAMMING, W.Richard Stevens,VOl 1,PE2. Web sites related to C socket programming, network programming ,JAVA network

programming, network simulator NS2.


Recommended