COMPUTER NETWORKS LAB MANUAL
May 28, 2016 | Author: PRIYA RAJI | Category: N/A
Short Description
ANNA UNIVERSITY FIFTH SEMESTER IT COMPUTER NETWORKS LAB MANUAL...
Description
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
K.L.N. COLLEGE OF ENGINEERING Pottapalayam Post - 630 612. Sivagangai District, Tamil Nadu.
DEPARTMENT OF INFORMATION TECHNOLOGY
IT6511-NETWORKS LABORATORY MANUAL
Staff In-Charges and Prepared by Mr.S.Ilangovan, ASP/IT Mr.S.Ramesh, AP2/IT III Year/V Semester (July 2015-November 2015)
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
IT6511
NETWORKS LABORATORY
LTPC 0 0 3 2
OBJECTIVES: The student should be made to: Learn socket programming. Be familiar with simulation tools. Have hands on experience on various networking protocols.
LIST OF EXPERIMENTS: 1. Implementation of Stop and Wait Protocol and Sliding Window Protocol. 2. Study of Socket Programming and Client – Server model 3. Write a code simulating ARP /RARP protocols. 4. Write a code simulating PING and TRACEROUTE commands 5. Create a socket for HTTP for web page upload and download. 6. Write a program to implement RPC (Remote Procedure Call) 7. Implementation of Subnetting . 8. Applications using TCP Sockets like a. Echo client and echo server b. Chat c. File Transfer 9. Applications using TCP and UDP Sockets like d. DNS e. SNMP f. File Transfer 10. Study of Network simulator (NS).and Simulation of Congestion Control Algorithms using NS 11. Perform a case study about the different routing algorithms to select the network path with its optimum and economical during data transfer. i. Link State routing ii. Flooding iii. Distance vector
TOTAL: 45 PERIODS
Staff In-Charge
HOD/IT
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
K.L.N. College of Engineering, Pottapalayam – 630612. Department of Information Technology LAB PLAN Subject Name: Networks Lab
Branch: IT
Subject Code: IT6511
Year/Sem/Sec: III/V/A
Name of the Faculty: Mr.S.Ramesh, M.E., M.B.A.,
Faculty Code: 10535027
Ex.No
Date
Name of the Experiment
1
01-07-15
Study of Socket Programming and Client – Server model.
2
08-07-15
Chat Application using TCP Sockets.
3
15-07-15
Echo client and echo server using TCP Sockets.
4
22-07-15
File transfer using TCP Sockets.
5
29-07-15
Write a code simulating PING commands.
6
05-08-15
Write a code simulating TRACEROUTE commands.
7
08-08-15
Write a program to implement RPC (Remote Procedure Call).
8
12-08-15
Implementation of Stop and Wait Protocol and Sliding Window Protocol.
9
19-08-15
Write a code simulating ARP /RARP protocols.
10
26-08-15
Create a socket for HTTP for web page upload and download.
11
02-09-15
Study of Network simulator (NS).
12
09-09-15
Two Nodes and four nodes creation using NS2.
13
16-09-15
Revision - 1
14
23-09-15
Revision - 2
15
30-09-15
Model Lab Exam
16
12-10-15
University Lab Exam
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
Staff In-charge
HOD/IT
K.L.N College Of Engineering, Pottapalayam – 630612 Department of Information Technology LAB PLAN Subject Name: Networks Lab
Branch: Information Technology
Subject Code: IT6511
Year/Sem/Sec: III/V/B
Name of the Faculty: Mr.S.ILANGOVAN,
Faculty Code: 10535021
Ex.No
Date
Name of the Experiment
1
03-07-15
Study of Socket Programming and Client – Server model.
2
10-07-15
Chat Application using TCP Sockets.
3
17-07-15
Echo client and echo server using TCP Sockets.
4
24-07-15
File transfer using TCP Sockets.
5
31-07-15
Write a code simulating PING commands.
6
07-08-15
Write a code simulating TRACEROUTE commands.
7
14-08-15
Write a program to implement RPC (Remote Procedure Call).
8
21-08-15
Implementation of Stop and Wait Protocol and Sliding Window Protocol.
9
28-08-15
Write a code simulating ARP /RARP protocols.
10
04-09-15
Create a socket for HTTP for web page upload and download.
11
11-09-15
Study of Network simulator (NS).
12
12-09-15
Two Nodes and four nodes creation using NS2.
13
18-09-15
Revision - 1
14
25-09-15
Revision - 2
15
09-10-15
Model Lab Exam
16
12-10-15
University Lab Exam
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
Staff In-charge
Ex.No.1a
HOD/IT
STUDY OF SOCKET PROGRAMMING
AIM: To study about socket programming for developing the client server application. DESCRIPTION A socket is an endpoint for communication. Two processes can communicate by creating sockets and sending messages between them. A socket type is uniquely determined by a triple. a= socket(addressfamily,type of socket,protocol) addressfamily=AF_INET type of socket=SOCK_STREAM (or) SOCK_DGRAM protocol= 0 (for system default protocol) a=unique descriptor In order to hold information about the socket, socket address structures are used. int bind (socket descriptor, socket address structure, sizeof(socketaddressstructure)) return 0 if OK,-1 on error int listen( int sockfd, int backlog) return 0 if OK,-1 on error int accept(int sockfd, void *addr, void *addrlen); return positive value if OK, -1 on error int connect(int sockfd, socket address structure, sizeof(socketaddressstructure))
RESULT: Thus the socket programming was studied.
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
Exp. No.1b
SOCKET CREATION
AIM To write a C program for creating a socket ALGORITHM 1.
Include the necessary header files.
2.
Declare 2 variables as TCP and UDP file descriptors for holding the values of TCP and UDP socket.
3.
Call the System function Socket ( ) with the following parameters type of family, type of socket and type of protocol for creating the socket.
4.
If the System function returns negative value then the print error message else print socket created with socket value.
Exp. No.1c
SOCKET BINDING
AIM To write a C program for socket binding ALGORITHM 1. Include the necessary header files. 2. Declare 2 variables as TCP and UDP file descriptors for holding the values of 3. TCP and UDP socket. 4. Call the System function socket() with the following parameters type of family, type of socket and type of protocol for creating the socket. 5. Call the system function bind() with the following parameters socket descriptor, socket address structure and size of socket address structure.
RESULT: Thus the socket creation and socket binding was performed.
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
Exp. No.2
CLIENT – SERVER CHAT USING TCP/IP
Aim: To write a C program for client – server chat using TCP Theory TCP TCP stands for Transaction Control Protocol. This is one of the transport layer protocols. TCP offers a connection-oriented, reliable, byte stream service. This also provides a good flow control and congestion control. The term connection-oriented means any two applications using TCP must establish a connection with each other before they can exchange data. This can be done by using three-way handshaking. Data is divided into small chunks and each chunk of data is called as Segments. The data sent using TCP follows a single route and it can be in out-of-order. The receiver will rearrange the data using the sequence numbers. Flow control is established by using a finite amount of buffer space on both sides. With this the receiver allows the sender to send only the amount of data it can accept in the buffer. TCP also provides error control. A checksum is maintained in the header and data.
Services provided by TCP • Connection- oriented: setup required between client, server • Reliable transport between sending and receiving process • Flow control: sender won’t overwhelm receiver • Congestion control: throttle sender when network overloaded Services not provided by TCP • Timing and minimum bandwidth Algorithm Server 1. Start the program. 2. Include all the necessary header files and declare necessary variables. 3. Create a stream socket “sersock” using socket() and check if the socket is created successfully or not. 4. Initialize the server socket structure variable – ser_ip(family, port & address). 5. Use bind() to assign the local socket address ser_ip to the socket identified by sersock. 6. Accept the request to connect from the client by using the accept() and store the socket information in nsersock. 7. Send and receive data to and from the client by using send () & recv() respectively. Print the received data. 8. Goto step 7 until client sends “exit”. 9. Close all open sockets. 10. Stop the program. Client 1. Start the program.
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in 2. Include all the necessary header files and declare necessary variables. 3. Create a stream socket “clisock” using socket() and check if the socket is created successfully of not. 4. Initialize the client socket structure variable – cli_ip(family, port & address). 5. Send a request to connect with the server using connect(). 6. Send and receive data to and from server using send() & recv() respectively. 7. Repeat step 6 until either of the users wants to quit by typing “exit”. 8. Close all open sockets. 9. Stop the program.
Program Serverchat import java.net.*; import java.io.*; public class Serverchat{ public static void main(String[]args)throws IOException{ ServerSocket sock=null; BufferedReader fromClient=null,fromUser=null; PrintWriter toClient=null; Socket client=null; try{ sock=new ServerSocket(4444); System.out.println("Server Ready"); client=sock.accept(); System.out.println("Client connected"); fromClient=new BufferedReader(new InputStreamReader(client.getInputStream())); toClient=new PrintWriter(client.getOutputStream()); fromUser=new BufferedReader(new InputStreamReader(System.in)); String line,Usermsg; while(true){ line=fromClient.readLine(); if((line==null) || (line.equals("bye"))) break; System.out.println("Client:" +line); System.out.print("me:"); Usermsg=fromUser.readLine(); toClient.println(Usermsg); toClient.flush(); } fromClient.close(); toClient.close(); client.close(); System.out.println("Client disconnected"); } catch(IOException ioe){ System.out.println(ioe); } } } Clientchat
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
import java.net.*; import java.io.*; public class Clientchat{ public static void main(String[]args)throws IOException{ BufferedReader fromServer=null,fromUser=null; PrintWriter toServer=null; Socket sock=null; try{ if(args.length==0) sock=new Socket(InetAddress.getLocalHost(),4444); else sock=new Socket(InetAddress.getByName(args[0]),4444); fromServer=new BufferedReader(new InputStreamReader(sock.getInputStream())); fromUser=new BufferedReader(new InputStreamReader(System.in)); toServer=new PrintWriter(sock.getOutputStream(),true); String Usermsg,Servmsg; System.out.println("Type \"bye\" to quit"); while(true){ System.out.print("me:"); Usermsg=fromUser.readLine(); if(Usermsg==null||Usermsg.equals("bye")){ toServer.println("bye"); break; } else toServer.println(Usermsg); Servmsg=fromServer.readLine(); System.out.println("Server:" +Servmsg); } fromUser.close(); fromServer.close(); toServer.close(); sock.close(); } catch(IOException ioe){ System.err.println(ioe); } } }
Result Thus the C program for client-server chat using TCP is written, entered, executed and the results are verified.
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
EX.NO:3
ECHO CLIENT AND SERVER USING TCP SOCKETS
AIM: To implementation of echo client server using TCP/IP ALGORITHM: 1.start the program 2 To create a socket in client to server. 3. 3he client establishes a connection to the server. 4. The client accept the connection and send data to server and the server to replay the echo message to the client 5. The client communicate the server to send the end of the message 6. Stop the program. Program Server
import java.net.*; import java.io.*; public class Serverecho{ public static void main(String[]args)throws IOException{ ServerSocket sock=null; BufferedReader fromClient=null; OutputStreamWriter toClient=null; Socket client=null; try{ sock=new ServerSocket(4444); System.out.println("Server Ready"); client=sock.accept(); System.out.println("Client connected"); fromClient=new BufferedReader(new InputStreamReader(client.getInputStream())); toClient=new OutputStreamWriter(client.getOutputStream()); String line; while(true){ line=fromClient.readLine(); if((line==null)||(line.equals("bye"))) break; System.out.println("client[" +line+ "]\n"); toClient.write("server[" +line+ "]\n"); toClient.flush(); } fromClient.close(); toClient.close();
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
client.close(); System.out.println("Client disconnected"); } catch(IOException ioe){ System.out.println(ioe); } }} Client import java.net.*; import java.io.*; public class Clientecho{ public static void main(String[]args)throws IOException{ BufferedReader fromServer=null,fromUser=null; PrintWriter toServer=null; Socket sock=null; try{ if(args.length==0) sock=new Socket(InetAddress.getLocalHost(),4444); else sock=new Socket(InetAddress.getByName(args[0]),4444); fromServer=new BufferedReader(new InputStreamReader(sock.getInputStream())); fromUser=new BufferedReader(new InputStreamReader(System.in)); toServer=new PrintWriter(sock.getOutputStream(),true); String Usermsg,Servmsg; System.out.println("Type \"bye\" to quit"); while(true){ System.out.println("Enter msg to server:"); Usermsg=fromUser.readLine(); if(Usermsg.equals("bye")){ toServer.println("bye"); break; } else toServer.println(Usermsg); Servmsg=fromServer.readLine(); System.out.println(Servmsg); } fromUser.close(); fromServer.close(); toServer.close(); sock.close(); } catch(IOException ioe){ System.err.println(ioe); } } } Result Thus the echo client server using TCP/IP was implemented successfully.
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
Ex.No : 4
File transfer using TCP sockets
Aim To write a java program for applaction using TCP Sockets
Algorithm 1.Start the program. 2.Get the frame size from the user 3.To create the frame based on the user request. 4.To send frames to server from the client side. 5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client. 6.Stop the program
Program Clientfile
import java.net.*; import java.io.*; import java.lang.String; public class ClientFile{ public static void main(String [] args)throws IOException{ int i; //String s="ServerFile.txt"; InputStream is=null; BufferedOutputStream bos=null; Socket sock=null; try{ if(args.length==0) sock=new Socket(InetAddress.getLocalHost(),4000); else sock=new Socket(InetAddress.getByName(args[0]),4000); System.out.println("Connecting..."); String s1="clientFile.txt"; File myfile = new File(s1); byte [] arrayy=new byte[1500]; is=sock.getInputStream(); bos=new BufferedOutputStream(new FileOutputStream(myfile)); i=is.read(arrayy,0,arrayy.length); bos.write(arrayy,0,i); bos.flush(); } catch(IOException ioe){ System.out.println(ioe); }
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
} }
Serverfile import java.net.*; import java.io.*; import java.lang.String; public class ServerFile{ public static void main(String [] args)throws IOException{ ServerSocket sock=null; BufferedInputStream bis=null; Socket client=null; OutputStream os=null; int a; try{ sock=new ServerSocket(4000); System.out.println("Waiting..."); client=sock.accept(); System.out.println("Server Ready"); System.out.println("Accepted connection:" +client); String s="ServerFile.txt"; File myfilee=new File(s); byte [] array=new byte[(int)myfilee.length()]; bis=new BufferedInputStream(new FileInputStream(myfilee)); a=bis.read(array,0,array.length); os=client.getOutputStream(); os.write(array,0,a); os.flush(); } catch(IOException ioe){ System.out.println(ioe); } } }
Result Thus the file transfer using TCP sockets was executed successfully.
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
EX-NO. 5
Write a Code simulating PING and TRACEROUTE Commands
Aim: To Write The java program for simulating ping and traceroute commands ALGORITHM: 1.Start the program. 2.Get the frame size from the user 3.To create the frame based on the user request. 4.To send frames to server from the client side. 5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client. 6.Stop the program Program //pingclient.java import java.io.*; import java.net.*; import java.util.Calendar; class pingclient { public static void main(String args[])throws Exception { String str; int c=0; long t1,t2; Socket s=new Socket("127.0.0.1",5555); DataInputStream dis=new DataInputStream(s.getInputStream()); PrintStream out=new PrintStream(s.getOutputStream()); while(cjava Clientrpc Enter String Calc
cseitquestions.blogspot.in | cseitquestions.blogspot.in | cseitquestions.blogspot.in
Result : Thus the program was implementing to implement RPC (remote procedure call)
Ex.No:8 Implementation of Stop and Wait Protocol and Sliding Window Protocol AIM: To write a java program to perform sliding window. ALGORITHM: 1.Start the program. 2.Get the frame size from the user 3.To create the frame based on the user request. 4.To send frames to server from the client side. 5.If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client. 6.Stop the program Program : import java.net.*; import java.io.*; import java.rmi.*; public class slidsender { public static void main(String a[])throws Exception { ServerSocket ser=new ServerSocket(10); Socket s=ser.accept(); DataInputStream in=new DataInputStream(System.in); DataInputStream in1=new DataInputStream(s.getInputStream()); String sbuff[]=new String[8]; PrintStream p; int sptr=0,sws=8,nf,ano,i; String ch; do { p=new PrintStream(s.getOutputStream()); System.out.print("Enter the no. of frames : "); nf=Integer.parseInt(in.readLine()); p.println(nf); if(nf
View more...
Comments