Aids NT Lab-1
Aids NT Lab-1
Aids NT Lab-1
NAME :
REGISTER NO :
VM NO : VM -
BRANCH : AI&DS
YEAR : II
SEMESTER : IV
➢ To promote centre of excellence through effectual Teaching and Learning, imparting the contemporary knowledge
centric education through innovative research in multidisciplinary fields.
Mission
➢ To impart quality technical skills through practicing, knowledge updating in recent technology and produce
professionals with multidisciplinary and leadership skills.
➢ To promote innovative thinking for design and development of software products of varying complexity withintelligence
to fulfil the global standards and demands.
➢ To inculcate professional ethics among the graduate and to adapt the changing technologies through lifelong learning.
An Autonomous Institution
Approved by AICTE, Affiliated to Anna University, Chennai.
ISO 9001:2015 Certified Institution, Accredited by NBA (BME, CSE, ECE, EEE, IT & MECH),
Accredited by NAAC.
#42, Avadi-Vel Tech Road, Avadi, Chennai- 600062, Tamil Nadu, India.
CERTIFICATE
Submitted for the University Practical Examination held on ………………... at VEL TECH MULTI
TECH Dr.RANGARAJAN Dr.SAKUNTHALA ENGINEERING COLLEGE, No.42, AVADI – VEL
TECH ROAD, AVADI, CHENNAI-600062.
Signature of Examiners
Date:………………
DEPARTMENT OF ARTIFICIAL INTELLIGENCE AND DATA SCIENCE
PO2 Problem Analysis: Identify, formulate, review research literature and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
PO3 Design / Development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet specified needs with appropriate consideration
for public health and safety, cultural, societal, and environmental considerations.
PO4 Conduct Investigations of Complex Problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
PO5 Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with
an understanding of the limitations.
PO6 The Engineer and Society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant tothe
professional engineering practice.
PO7 Environment and sustainability: Understand the impact of the professional engineering solutions
in societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development.
PO8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
PO9 Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO11 Project Management and Finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one’s own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
PO12 Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PROGRAM EDUCATIONAL OBJECTIVES(PEOs)
Train the graduates with the potential of strong knowledge in the respective field and to create
PEO1
innovative multidisciplinary solutions for challenges in the society.
Groom the engineers to understand, analyse different nature of data and use Machine Learning
PEO2 techniques to develop software systems with varying complexity for data intensive
applications.
To practice professionalism among the graduates and reflect good leadership skills with ethical
PEO3
standards and continued professional development through lifelong learning.
PROGRAMMESPECIFICOUTCOMES(PSOs)
PSO’s PROGRAMMESPECIFICOUTCOMES(PSOs)
To impart theoretical knowledge in the respective field along with recent industrial tools
PSO1
and techniques to solve societal problems
Apply the core competency obtained in the field of Machine Learning for analysis, design
PSO2
and development of computing systems for multi-disciplinary problems
Acquire knowledge in the field of intelligence, deep learning and develop software
PSO3
solutions for security and analytics of large volume of data.
COURSE OBJECTIVES
COURSE OUTCOMES
At the end of the course, the student should be able to
Course CO Statements
Outcome
CO – PO & PSO
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
CO1 3 3 3 3 3 2 2 2 2 1 1 1 3 2 1
CO2 3 3 3 3 2 2 2 2 2 1 1 1 2 2 1
CO3 3 3 3 3 3 2 2 2 1 1 1 1 2 2 1
CO4 3 3 3 3 3 2 2 2 1 1 1 1 2 2 1
CO5 3 3 3 3 3 1 1 1 1 1 1 1 1 1 1
CO 3 3 3 3 3 2 2 2 1 1 1 1 2 2 1
LIST OF
EXPERIMENTS
Ex. Page
Date List of Exercises CO Marks signature
No No
a. Implementations of Sliding Window CO1
1 Protocol
b. Implementation of Stop and Wait Protocol CO1
AIM:
To write a java program to perform Sliding Window protocol.
ALGORITHM:
as acknowledgements arrive.
STEP 3: Receiver sliding window waits for a specific frame to arrive in a specific
order andframe arriving out of order is discarded and needs to be resent.
STEP 4: Commence transmission.
STEP 5: Deal with damaged or lost frame.
STEP 6: Deal with damaged or lost acknowledgement.
STEP 7: Deal with delayed acknowledgement.
STEP 8: Update sender windows
STEP 9: Stop the program.
PROGRAM:
SENDER PROGRAM
import java.net.*;
import java.io.*;
import java.rmi.*;
class slidesender
{
public static void main(String a[])throws Exception
{
ServerSocketser=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;
intsptr=0,sws=8,nf,ano,i; String ch;
do
{
p=new PrintStream(s.getOutputStream());
7
System.out.print("Enter the no. of frames : ");
nf=Integer.parseInt(in.readLine()); p.println(nf);
if(nf<=sws-1)
{
System.out.println("Enter "+nf+" Messages to be send\n"); for(i=1;i<=nf;i++)
{
sbuff[sptr]=in.readLine();
p.println(sbuff[sptr]);
sptr=++sptr%8;
}
sws-=nf;
System.out.print("Acknowledgment received"); ano=Integer.parseInt(in1.readLine());
System.out.println(" for "+ano+" frames"); sws+=nf;
}
else
{
System.out.println("The no. of frames exceeds window size"); break;
}
System.out.print("\nDo you wants to send some more frames : "); ch=in.readLine();
p.println(ch);
}
while(ch.equals("yes"));
s.close();
}
}
RECEIVER PROGRAM
import java.net.*;
import java.io.*;
class slidereceiver
{
public static void main(String a[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10);
DataInputStream in=new DataInputStream(s.getInputStream());
PrintStream p=new PrintStream(s.getOutputStream());
inti=0,rptr=-1,nf,rws=8;
String rbuf[]=new String[8];
String ch;
System.out.println();
do
{
nf=Integer.parseInt(in.readLine());
if(nf<=rws-1)
{
for(i=1;i<=nf;i++)
{
8
rptr=++rptr%8;
rbuf[rptr]=in.readLine();
System.out.println("The received Frame " +rptr+" is : "+rbuf[rptr]);
}
rws-=nf;
System.out.println("\nAcknowledgment sent\n");
p.println(rptr+1);
rws+=nf;
}
else
break;
ch=in.readLine();
}
while(ch.equals("yes"));
}
}
OUTPUT:
Sender Window
9
Receiver Window
RESULT:
Thus the program for implementation of sliding window protocol was executed and the
output is verified successfully.
INFERENCE:
10
EXNO: 1B DATE:
AIM:
To write a java program to perform stop and wait protocol.
ALGORITHM:
PROGRAM
SENDER PROGRAM
import java.io.*;
import java.net.*;
public class Sender{
Socket sender;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,str, msg;
int n,i=0,sequence=0;
Sender(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Waiting for Connection....");
sender = new Socket("localhost",2004);
sequence=0;
11
out=new ObjectOutputStream(sender.getOutputStream());
out.flush();
in=new ObjectInputStream(sender.getInputStream());
str=(String)in.readObject();
System.out.println("reciver > "+str);
System.out.println("Enter the data to send....");
packet=br.readLine();
n=packet.length();
do{
try{
if(i<n){
msg=String.valueOf(sequence);
msg=msg.concat(packet.substring(i,i+1));
}
else if(i==n){
msg="end";out.writeObject(msg);break;
}
out.writeObject(msg);
sequence=(sequence==0)?1:0;
out.flush();
System.out.println("data sent>"+msg);
ack=(String)in.readObject();
System.out.println("waiting for ack.....\n\n");
if(ack.equals(String.valueOf(sequence))){
i++;
System.out.println("receiver > "+" packet recieved\n\n");
}
else{
System.out.println("Time out resending data....\n\n");
sequence=(sequence==0)?1:0;
}
}catch(Exception e){}
}while(i<n+1);
System.out.println("All data sent. exiting.");
}catch(Exception e){}
finally{
try{
in.close();
out.close();
sender.close();
}
12
catch(Exception e){}
}
}
public static void main(String args[]){
Sender s=new Sender();
s.run();
}
}
RECEIVER PROGRAM
import java.io.*;
import java.net.*;
public class Reciever{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Reciever(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2004,10);
System.out.println("waiting for connection...");
connection=reciever.accept();
sequence=0;
System.out.println("Connection established :");
out=new ObjectOutputStream(connection.getOutputStream());
out.flush();
in=new ObjectInputStream(connection.getInputStream());
out.writeObject("connected .");
do{
try{
packet=(String)in.readObject();
if(Integer.valueOf(packet.substring(0,1))==sequence){
data+=packet.substring(1);
sequence=(sequence==0)?1:0;
System.out.println("\n\nreceiver >"+packet);
}
else
{
System.out.println("\n\nreceiver >"+packet +" duplicate data");
}
if(i<3){
out.writeObject(String.valueOf(sequence));i++;
}
else{
13
out.writeObject(String.valueOf((sequence+1)%2));
i=0;
}
}
catch(Exception e){}
}while(!packet.equals("end"));
System.out.println("Data recived="+data);
out.writeObject("connection ended .");
}
catch(Exception e){}
finally{
try{
in.close();
out.close();
reciever.close();
}
catch(Exception e){}
}
}
public static void main(String args[]){
Reciever s=new Reciever();
while(true){
s.run();
}
}
}
OUTPUT
SENDER OUTPUT
14
RECEIVER OUTPUT
RESULT:
Thus the program for implementation of stop and wait protocol was executed and the
output is verified successfully.
INFERENCE:
15
EXNO: 2 DATE:
STUDY OF SOCKET PROGRAMMING CLIENT-SERVER MODEL
To write a socket program to send Date and Time from Server to Client.
ALGORITHM:
16
SERVER PROGRAM
filename: tcpserver.java
import java.io.*;
import java.net.*;
import java.util.*;
class tcpserver
{
public static void main(String args[]) throws Exception
{
ServerSocket soc=new ServerSocket(10000);
System.out.println("Server is Ready......Waiting for Client Request ......");
while(true) {
Socket so=soc.accept();
OutputStream os=so.getOutputStream();
DataOutputStream dos=new DataOutputStream(os);
Date d=new Date();
dos.writeUTF(d.toString());
dos.close();
soc.close();
so.close();
}
}}
CLIENT PROGRAM
filename: tcpclient.java
import java.io.*;
import java.net.*;
class tcpclient
{
public static void main(String args[])throws Exception
{
try
{
Socket ss=new Socket(args[0],10000);
InputStream is=ss.getInputStream();
DataInputStream dis=new DataInputStream(is);
String info=dis.readUTF();
System.out.println("Message From Server");
System.out.println("Received at Client");
System.out.println("\t\t"+info);
dis.close();
ss.close();
}
catch(Exception e)
{
System.out.println("Inside Exception");
}
}}
17
OUTPUT:
CLIENT WINDOW
SERVER WINDOW
RESULT:
Thus the socket program to send Date and Time from Server to Client was executed and
output is verified successfully.
INFERENCE:
18
EXNO: 3A DATE:
IMPLEMENTATION OF ARP PROTOCOLS
AIM:
To write a java program for implementing the Address Resolution Protocol (ARP).
DESIGN APPROACH:
ARP is a low-level protocol used to bind a address dynamically. It allows a host to find a
physical address of a target host on the same physical network given only its IP address. ARP
hides the underlying network physical addressing. It can be thought of as aprt of physical network
system and not the internet protocols. ARP broadcasts special packets with destination‘s IP
address to all hosts. The destination host only will respond with physical address. When the
response is received, the sender use the physical address of destination host to send all the packets.
Hardware Type(16 bits): The type of interface the sender seeks an answer for.
Protocol Type(16 bits): The high level software address to be provided.
HLEN(8 bits)- Length of the arbitrary physical address.
PLEN(8 bits)-Length of the arbitrary protocol address
OPERATION(16 bits)-The specific type of operation required-ARP.request-1,
ARP.response-2
SENDER HA(6 octets)-The sender‘s actual hardware address scalable upto 6 bytes.
SENDER IP(4 octets)-The sender‘s IP address, always 32 bits.
TARGET HA(6 octets)-The destination node‘s HA, scalable to 6 bytes.
TARGET IP(4 octets)-The destination node‘s IP address, always 32 bits.
19
FUNCTIONS USED:
Implementation of ARP
import java.io.*;
import java.net.*;
class Corarp
{
public static void main(String args[])throws Exception
{
try
{
BufferedReader in=null; FileOutputStream fout;
FileInputStream fin;
Runtime r=Runtime.getRuntime(); Process p=r.exec("arp -a");
in=new BufferedReader(new InputStreamReader(p.getInputStream()));
fout=new FileOutputStream("out.data");
PrintWriter pw=new PrintWriter(fout,true);
String line;
while((line=in.readLine())!=null)
{
System.out.println(line);
pw.println(line);
}
fin=new FileInputStream("out.data");
BufferedReader bin1=new
BufferedReader(newInputStreamReader(System.in));
BufferedReader bin=new BufferedReader(new InputStreamReader(fin));
20
String l,l1,l2;
l1=bin1.readLine();
l1=" "+l1;
l=bin.readLine();
while((l=bin.readLine())!=null)
{
if(l.startsWith(l1))
{
l2=l.substring(25,41);
System.out.println(l2);
break;
}
}
in.close();
}
catch(IOException e)
{
}
}
}
21
OUTPUT:
RESULT:
Thus the program to implement Address Resolution Protocol was executed and the
output was verified successfully.
INFERENCE:
22
EXNO: 3B DATE:
IMPLEMENTATION OF RARP PROTOCOLS
AIM:
To write a java program for implementing the Reverse Address Resolution Protocol
(RARP)
DESIGN APPROACH:
RARP does the reverse operation of ARP, when we give the Physical address RARP
provides the corresponding IP address
Hardware Type(16 bits): The type of interface the sender seeks an answer for.
Protocol Type(16 bits): The high level software address to be provided.
HLEN(8 bits)- Length of the arbitrary physical address.
PLEN(8 bits)-Length of the arbitrary protocol address
OPERATION(16 bits)-The specific type of operation required-ARP.request-1,
ARP.response-2
SENDER HA(6 octets)-The sender‘s actual hardware address scalable upto 6 bytes.
SENDER IP(4 octets)-The sender‘s IP address, always 32 bits.
TARGET HA(6 octets)-The destination node‘s HA, scalable to 6 bytes.
23
FUNCTIONS USED:
PROGRAM:
import java.io.*;
import java.net.*;
class Corrarp
{
public static void main(String args[])throws Exception
{
try
{
BufferedReader in=null;
FileOutputStream fout;
FileInputStream fin;
Runtime r=Runtime.getRuntime();
Process p=r.exec("arp -a");
in=new BufferedReader(new InputStreamReader(p.getInputStream()));
fout=new FileOutputStream("out.data");
PrintWriter pw=new PrintWriter(fout,true);
String line;
while((line=in.readLine())!=null)
{
System.out.println(line);
pw.println(line);
}
fin=new FileInputStream("out.data");
BufferedReader bin1=new BufferedReader(new
InputStreamReader(System.in));
BufferedReader bin=new BufferedReader(new InputStreamReader(fin));
String l,l1,l2;
l1=bin1.readLine();
24
l=bin.readLine();
while((l=bin.readLine())!=null)
{
if(l.startsWith("Int")||l.startsWith(" Int"))
{
continue a;
}
l2=l.substring(24,41);
if(l2.equals(l1))
{
System.out.println(l); break;
}
}
in.close();
}
catch(IOException e)
{
}
}
}
25
OUTPUT:
RESULT:
Thus the program for implementing Reverse Address Resolution Protocol was executed
and the output is verified successfully.
INFERENCE:
26
EXNO: 4A DATE:
IMPLEMENTATION OF PING COMMAND
AIM:
DESIGN APPROACH:
This method executes the program specified by the ‘prgname’ as a separate process. An
object of type process is returned that describes the new process.
• IP address
• Number of bytes of data sent
• Round Trip Time measured in millisec
• TTL(Time to Live)- this value decreases by one when it passes through each node,server
or router, when it drops to zero, the packet is discarded.
ALGORITHM:
27
PROGRAM:
import java.net.*;
import java.io.*;
class ping
{
public static void main(String a[]) throws Exception
{
BufferedReader in =null;
try
{
Runtime r = Runtime.getRuntime();
Process p = r.exec("ping 132.147.205.18");
if(p==null)
{
System.out.println("There is no reply");
}
in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line;
while((line = in.readLine())!=null)
{
System.out.println(line);
}
in.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
}
}
28
OUTPUT:
RESULT:
Thus the program to implement ping command was executed and the output is verified
successfully.
INFERENCE:
29
EXNO: 4B DATE:
IMPLEMENTATION OF TRACEROUTE COMMAND
AIM:
DESIGN APPROACH:
In computing, traceroute is a computer network diagnostic tool for displaying the route
and measuring transit delays of packets across an Internet Protocol (IP) network. The history of
the route is recorded as the round-trip times of the packets received from each successive host
(remote node) in the route (path); the sum of the mean times in each hop indicates the total time
spent to establish the connection. Traceroute proceeds unless all (three) sent packets are lost more
than twice, then the connection is lost and the route cannot be evaluated. Ping, on the other hand,
only computes the final round-trip times from the destination point.
ALGORITHM:
PROGRAM:
import java.net.*;
import java.io.*;
class ping
{
public static void main(String a[]) throws Exception
{
BufferedReader in =null; try
{
Runtime r = Runtime.getRuntime();
Process p = r.exec("tracert 132.147.205.18");
if(p==null)
{
System.out.println("There is no reply");
}
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while((line = in.readLine())!=null)
{
30
System.out.println(line);
}
in.close();
}
catch(IOException e)
{
System.out.println(e.toString());
}
}
}
OUTPUT:
RESULT:
Thus the program for implement the TRACEROUTE command was executed and the output
was verified successfully.
INFERENCE:
31
EXNO: 5 DATE:
UPLOADING AND DOWNLOADING IMAGE FILE USING
SOCKET PROGRAMMING
AIM:
To write a java program to create socket for uploading and downloading an image file.
ALGORITHM:
CLIENT
import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Client
{
public static void main(String args[]) throws Exception
{
Socket soc;
BufferedImage img = null; soc=new Socket("localhost",4000);
System.out.println("Client is running. ");
try
{
System.out.println("Reading image from disk. ");
img = ImageIO.read(new File("digital_image_processing.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
32
baos.flush();
byte[] bytes = baos.toByteArray();
baos.close();
System.out.println("Sending image to server. ");
OutputStream out = soc.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
dos.writeInt(bytes.length);
dos.write(bytes, 0, bytes.length);
System.out.println("Image sent to server. ");
dos.close();
out.close();
}
catch (Exception e)
{
System.out.println("Exception: " + e.getMessage());
soc.close();
}
soc.close();
}
}
SERVER
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket server=null;
Socket socket;
server=new ServerSocket(4000);
System.out.println("Server Waiting for image");
socket=server.accept();
System.out.println("Client connected.");
InputStream in = socket.getInputStream();
DataInputStream dis = new DataInputStream(in);
int len = dis.readInt();
System.out.println("Image Size: " + len/1024 + "KB");
byte[] data = new byte[len];
dis.readFully(data);
dis.close();
in.close();
InputStream ian = new ByteArrayInputStream(data);
BufferedImage bImage = ImageIO.read(ian); JFrame
33
f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel();
l.setIcon(icon);
f.add(l);
f.pack();
f.setVisible(true);
}}
34
OUTPUT
CLIENT
SERVER
RESULT:
Thus the program for HTTP web client program to download a web page using TCP
socket was executed and the output is verified successfully.
INFERENCE:
35
EXNO: 6A DATE:
APPLICATIONS USING TCP SOCKETS
IMPLEMENTATION OF ECHO
AIM:
To write a Network Socket program for implementing the echo operation.
ALGORITHM:
36
SERVER PROGRAM:
import java.io.*;
import java.net.*;
import java.lang.String.*;
public class Secho
{
public static void main(String args[]) throws Exception
{
ServerSocket ss =new ServerSocket(123);
Socket s=ss.accept();
DataInputStream in= new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String str;
System.out.println("\nSERVER SIDE!...");
while(true)
{
str=in.readLine();
out.writeBytes(str+"\n");
System.out.println("Msg from Client");
System.out.println(str+"\n");
}
}
}
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
import java.lang.String.*;
public class Cecho
{
public static void main(String args[]) throws Exception
{
DataInputStream in=new DataInputStream (System.in);
Socket s=new Socket("LocalHost",123);
DataInputStream inecho=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String str;
System.out.println("\nCLIENT SIDE!...\nType EXIT TO QUIT\nEnter Client Msg");
while((str=in.readLine())!=null)
{
out.writeBytes(str+"\n");
if(str.equals("exit"))
{
out.writeBytes("\nClient Terminated");
break;
}
37
else
{
System.out.println("\nEcho From Server");
System.out.print(str+"\n");
System.out.println("\nCLIENT SIDE!...\nEnter Client Msg")
}
}}
OUTPUT::
SERVER:
38
CLIENT:
RESULT:
Thus, the program for implementation of ECHO was executed and output is verified
successfully.
INFERENCE:
39
EXNO: 6B DATE:
CHAT APPLICATION
AIM:
To write a network program for implementing chat using TCP socket.
ALGORITHM:
SERVER PROGRAM:
import java.io.*;
import java.net.*;
public class chatserver
{
public static void main(String args[])throws Exception
{
DataInputStream din=null;
DataOutputStream dout=null;
Socket c=null;
ServerSocket m=null;
DataInputStream stdin=new DataInputStream(System.in);
try
{
m=new ServerSocket(68);
c=m.accept();
din=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(Exception e)
{
}
while(c!=null)
{
String m2; System.out.println("Server");
while(true)
{
String m1=din.readLine();
40
System.out.println("Message from client.."+m1);
System.out.println("\n\n Enter the message...");
m2=stdin.readLine();
dout.writeBytes(""+m2);
dout.writeBytes("\n");
}
}
din.close();
dout.close();
c.close();
m.close();
}
}
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
public class chatclient
{
public static void main(String args[])throws Exception
{
Socket c=null;
DataInputStream uin=null;
DataInputStream din=null;
DataOutputStream dout=null;
try
{
c=new Socket("localhost",68);
uin=new DataInputStream(System.in);
din=new DataInputStream(c.getInputStream());
dout=new DataOutputStream(c.getOutputStream());
}
catch(Exception e)
{
}
if(c!=null)
{
String inp;
System.out.println("Enter the message:");
while((inp=uin.readLine())!=null)
{
dout.writeBytes(""+inp);
dout.writeBytes("\n");
System.out.println("Echoed message from server.."+din.readLine());
System.out.println("Enter ur message:");
}
}
41
din.close();
dout.close();
c.c lose();
}
}
OUTPUT:
CLIENT
SERVER:
RESULT:
Thus the program for CHAT APPLICATION was executed and output is verified
successfully.
INFERENCE:
42
EXNO: 6C Date:
FILE TRANSFER USING TCP SOCKET
AIM:
ALGORITHM:
SERVER:
CLIENT:
PROGRAM
FILE CLIENT
import java.io.*;
import java.net.*;
import java.util.*;
class Clientfile
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
43
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the file name:");
String str=in.readLine();
dout.writeBytes(str+'\n');
System.out.println("Enter the new file name:");
String str2=in.readLine();
String str1,ss;
FileWriter f=new FileWriter(str2);
char buffer[];
while(true)
{
str1=din.readLine();
if(str1.equals("-1")) break;
System.out.println(str1);
buffer=new char[str1.length()];
str1.getChars(0,str1.length(),buffer,0);
f.write(buffer);
}
f.close();
clsct.close();
}
catch (Exception e)
{
System.out.println(e);
}}}
FILE SERVER
import java.io.*;
import java.net.*;
import java.util.*;
class Serverfile
{
public static void main(String args[])
{
try
{
ServerSocket obj=new ServerSocket(139);
while(true)
{
Socket obj1=obj.accept();
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
FileReader f=new FileReader(str);
BufferedReader b=new BufferedReader(f);
String s;
44
while((s=b.readLine())!=null)
{
System.out.println(s);
dout.writeBytes(s+'\n');
}
f.c lose();
dout.writeBytes("-1\n");
}}
catch(Exception e)
{ System.out.println(e);}
}}
OUTPUT:
CLIENT
45
SERVER
RESULT:
Thus the program for FILE TRANSFER was executed and the output is verified
successfully.
INFERENCE:
46
EXNO: 7 DATE:
IMPLEMENTATION OF DNS USING UDP SOCKETS
AIM:
ALGORITHM:
SERVER
CLIENT
STEP 7: Stop
47
PROGRAM
import java.io.*;
import java.net.*;
public class udpdnsserver
{
private static int indexOf(String[] array, String str)
{
str = str.trim();
for (int i=0; i < array.length; i++)
{
if (array[i].equals(str))
return i;
}
return -1;
}
public static void main(String arg[])throws IOException
{
String[] hosts = {"yahoo.com", "gmail.com","cricinfo.com", "facebook.com"};
String[] ip = {"68.180.206.184", "209.85.148.19","80.168.92.140",
"69.63.189.16"};
System.out.println("Press Ctrl + C to Quit");
while (true)
{
DatagramSocket serversocket=new DatagramSocket(1362);
byte[] senddata = new byte[1021];
byte[] receivedata = new byte[1021];
DatagramPacket recvpack = new DatagramPacket(receivedata,
receivedata.length);
serversocket.receive(recvpack);
String sen = new String(recvpack.getData());
InetAddress ipaddress = recvpack.getAddress();
int port = recvpack.getPort();
String capsent;
System.out.println("Request for host " + sen);
if(indexOf (hosts, sen) != -1)
capsent = ip[indexOf (hosts, sen)];
else
capsent = "Host Not Found";
senddata = capsent.getBytes();
DatagramPacket pack = new DatagramPacket(senddata,
senddata.length,ipaddress,port);
serversocket.send(pack);
serversocket.close();
}
}
}
48
//UDP DNS Client -- udpdnsclient.java
import java.io.*;
import java.net.*;
public class udpdnsclient
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
DatagramSocket clientsocket = new DatagramSocket();
InetAddress ipaddress;
if (args.length == 0)
ipaddress = InetAddress.getLocalHost();
else
ipaddress = InetAddress.getByName(args[0]);
byte[] senddata = new byte[1024];
byte[] receivedata = new byte[1024];
int portaddr = 1362;
System.out.print("Enter the hostname : ");
String sentence = br.readLine();
Senddata = sentence.getBytes();
DatagramPacket pack = new DatagramPacket
(senddata,senddata.length, ipaddress,portaddr);
clientsocket.send(pack);
DatagramPacket recvpack =new
DatagramPacket(receivedata,receivedata.length);
clientsocket.receive(recvpack);
String modified = new String(recvpack.getData());
System.out.println("IP Address: " + modified);
clientsocket.close();
}
OUTPUT
SERVER
$ javac udpdnsserver.java
$ java udpdnsserver
49
CLIENT
$ javac udpdnsclient.java
$ java udpdnsclient
IP Address: 68.180.206.184
$ java udpdnsclient
IP Address: 80.168.92.140
$ java udpdnsclient
RESULT:
Thus the program for implementation of DNS was executed and the output is
verified successfully.
INFERENCE:
50
EXNO: 8 DATE:
STUDY OF NETWORK SIMULATOR
AIM:
To study the network simulator and to simulate the congestion control mechanisms.
PROCEDURE:
An NS script starts with making a Simulator object instance.
• $ns color fid color: is to set color of the packets for a flow specified by the flow id(fid).
This member function of "Simulator" object is for the NAM display, and has no effect
on the actual simulation.
• $ns namtrace-all file-descriptor: This member function tells the simulator to record
simulation traces in NAM input format. It also gives the file name that the trace will be
written to later by the command $ns flush-trace. Similarly, the member function trace-
all is for recording the simulation trace in a general format.
• proc finish {}: is called after this simulation is over by the command $ns at 5.0 "finish".
In this function, post-simulation processes are specified.
• set n0 [$ns node]: The member function node creates a node. A node in NS is compound
object made of address and port classifiers (described in a later section). Users can create
a node by separately creating an address and a port classifier objects and connecting
them together. However, this member function of Simulator object makes the job easier.
To see how a node is created, look at the files: "ns-2/tcl/libs/ns- lib.tcl" and "ns-
2/tcl/libs/ns-node.tcl".
51
• $ns duplex-link node1 node2 bandwidth delay queue-type: creates two simplex linksof
specified bandwidth and delay, and connects the two specified nodes. In NS, theoutput
queue of a node is implemented as a part of a link, therefore users should specify the
queue-type when creating links. In the above simulation script, DropTail queue is used.
If the reader wants to use a RED queue, simply replace the word DropTail with RED.
The NS implementation of a link is shown in a later section. Like a node, a link is a
compound object, and users can create its sub-objects and connect them and the nodes.
Link source codes can be found in "ns-2/tcl/libs/ns-lib.tcl" and "ns-2/tcl/libs/ns-link.tcl"
files. One thing to note is that you can insert error modules in a link component to
simulate a lossy link (actually users can make and insert any network objects). Refer to
the NS documentation to find out how to do this.
• $ns queue-limit node1 node2 number: This line sets the queue limit of the two simplex
links that connect node1 and node2 to the number specified. At this point, the authors
do not know how many of these kinds of member functions of Simulator objects are
available and what they are. Please take a look at "ns-2/tcl/libs/ns-lib.tcl" and "ns-
2/tcl/libs/ns-link.tcl", or NS documentation for more information.
• $ns duplex-link-op node1 node2 ...: The next couple of lines are used for the NAM
display. To see the effects of these lines, users can comment these lines out and try the
simulation.
Now that the basic network setup is done, the next thing to do is to setup traffic agents such as
TCP and UDP, traffic sources such as FTP and CBR, and attach them to nodes and agents
respectively.
• set tcp [new Agent/TCP]: This line shows how to create a TCP agent. But in general, users can
create any agent or traffic sources in this way. Agents and traffic sources are in fact basic objects
(not compound objects), mostly implemented in C++ and linked to OTcl. Therefore, there are
no specific Simulator object member functions that create these object instances. To create
agents or traffic sources, a user should know the class names these objects (Agent/TCP,
Agnet/TCPSink, Application/FTP and so on). This information can be found in the NS
documentation or partly in this documentation. But one shortcut is to look at the "ns-
2/tcl/libs/ns-default.tcl" file. This file contains the default configurable parameter value settings
for available network objects. Therefore, it works as a good indicator of what kind of network
objects are available in NS and what are the configurable parameters.
• $ns attach-agent node agent: The attach-agent member function attaches an agent object
created to a node object. Actually, what this function does is call the attach member
function of specified node, which attaches the given agent to itself. Therefore, a user can
do the same thing by, for example, $n0 attach $tcp. Similarly, each agent object has a
member function attach-agent that attaches a traffic source object to itself.
• $ns connect agent1 agent2: After two agents that will communicate with each other are
created, the next thing is to establish a logical network connection between them. This
line establishes a network connection by setting the destination address to each others'
network and port address pair.
Assuming that all the network configuration is done, the next thing to do is write a simulation
scenario (i.e. simulation scheduling). The Simulator object has many scheduling member
52
functions. However, the one that is mostly used is the following:
• $ns at time "string": This member function of a Simulator object makes the scheduler
(scheduler_ is the variable that points the scheduler object created by [new Scheduler]
command at the beginning of the script) to schedule the execution of the specified string
at given simulation time. For example, $ns at 0.1 "$cbr start" will make the scheduler
call a start member function of the CBR traffic source object, which starts the CBR to
transmit data. In NS, usually a traffic source does not transmit actual data, but it notifies
the underlying agent that it has some amount of data to transmit, and the agent, just
knowing how much of the data to transfer, creates packets and sends them.
After all network configuration, scheduling and post-simulation procedure specifications are
done, the only thing left is to run the simulation. This is done by $ns run.
53
PROGRAM:
55
OUTPUT
RESULT:
Thus the NS2 simulation for congestion control was successfully completed.
INFERENCE:
56
EXNO: 9A DATE:
AIM:
ALGORITHM:
57
PROGAM:
#Define the queue size for the link between node G and r
$ns queue-limit $G $r 5
#Create a TCP agent and attach it to node s1 set tcp1 [new Agent/TCP/Reno]
$ns attach-agent $s1 $tcp1
$tcp1 set window_ 8
$tcp1 set fid_1
58
#Create a TCP agent and attach it to node s2 set tcp2 [new Agent/TCP/Reno]
$ns attach-agent $s2 $tcp2
$tcp2 set window_ 8
$tcp2 set fid_2
#Create a TCP agent and attach it to node s3 set tcp3 [new Agent/TCP/Reno]
$ns attach-agent $s3 $tcp3
$tcp3 set window_ 4
$tcp3 set fid_3
OUTPUT
$ ns TCP.tcl
60
RESULT:
Thus the simulation of TCP performance was done using NS2 successfully.
INFERENCE:
61
EXNO: 9B DATE:
AIM:
ALGORITHM:
62
PROGRAM
#Create a UDP agent and attach it to node n1 set udp1 [new Agent/UDP]
$udp1 set class_ 2
$ns attach-agent $n1 $udp1
63
# Create a CBR traffic source and attach it to udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
#Execute nam on the trace file exec nam -a out.nam & exit
0
}
64
OUTPUT
$ ns UDP.tcl
RESULT:
Thus the simulation of UDP performance was done using NS2 successfully.
INFERENCE:
65
EXNO: 10A DATE:
AIM:
ALGORITHM:
PROGRAM:
66
for { set i 0 } { $i < 12} { incr i 1 } {
set n($i) [$ns node]}
for {set i 0} {$i < 8} {incr i} {
$ns duplex-link $n($i) $n([expr $i+1]) 1Mb 10ms DropTail }
$ns duplex-link $n(0) $n(8) 1Mb 10ms DropTail
$ns duplex-link $n(1) $n(10) 1Mb 10ms DropTail
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto DV
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run
67
OUTPUT
RESULT:
Thus the Distance Vector Routing Algorithm was Simulated and studied.
INFERENCE:
68
EXNO: 10B DATE:
AIM:
ALGORITHM:
PROGRAM:
69
$ns duplex-link $n(0) $n(9) 1Mb 10ms DropTail
$ns duplex-link $n(9) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(10) $n(11) 1Mb 10ms DropTail
$ns duplex-link $n(11) $n(5) 1Mb 10ms DropTail
set udp0 [new Agent/UDP]
$ns attach-agent $n(0) $udp0
set cbr0 [new Application/Traffic/CBR]
$cbr0 set packetSize_ 500
$cbr0 set interval_ 0.005
$cbr0 attach-agent $udp0
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp0 $null0
set udp1 [new Agent/UDP]
$ns attach-agent $n(1) $udp1
set cbr1 [new Application/Traffic/CBR]
$cbr1 set packetSize_ 500
$cbr1 set interval_ 0.005
$cbr1 attach-agent $udp1
set null0 [new Agent/Null]
$ns attach-agent $n(5) $null0
$ns connect $udp1 $null0
$ns rtproto LS
$ns rtmodel-at 10.0 down $n(11) $n(5)
$ns rtmodel-at 15.0 down $n(7) $n(6)
$ns rtmodel-at 30.0 up $n(11) $n(5)
$ns rtmodel-at 20.0 up $n(7) $n(6)
$udp0 set fid_ 1
$udp1 set fid_ 2
$ns color 1 Red
$ns color 2 Green
$ns at 1.0 "$cbr0 start"
$ns at 2.0 "$cbr1 start"
$ns at 45 "finish"
$ns run
70
OUTPUT
RESULT:
Thus the Distance vector Routing Algorithm was simulated and studied.
INFERENCE:
71
EXNO: 11 DATE:
ALGORITHM:
SENDER
RECEIVER
72
PROGRAM
Go Back N Sender
import java.io.*;
import java.net.*;
public class GBNSend
{
String output[] = new String[7];
void sendMsg(BufferedReader buff, BufferedReader in, PrintWriter out, int x)
throws Exception
{
try
{
for(int i=x; i<7; i++)
{
System.out.print("Content for frame" + i + " : ");
output[i] = in.readLine();
out.println(output[i]);
out.flush();
}
}
catch(Exception e)
{
System.out.println("exception is" + e);
}
}
catch(Exception e)
{
System.out.println("exception is" + e);
}
}
OUTPUT:
Sender
Receiver
RESULT:
Thus the java program to simulate Go-Back-N ARQ was done and output verified.
INFERENCE:
75
EXNO: 12 DATE:
AIM:
ALGORITHM:
PROGRAM:
import java.util.Scanner;
class CRC
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m,g[],n,d[],z[],r[],msb,i,j,k;
System.out.print("Enter no. of data bits : ");
n=sc.nextInt();
System.out.print("Enter no. of generator bits : ");
m=sc.nextInt();
d=new int[n+m];
g=new int[m];
System.out.print("Enter data bits : ");
for(i=0;i<n;i++)
d[i]=sc.nextInt();
System.out.print("Enter generator bits : ");
for(j=0;j<m;j++)
g[j]=sc.nextInt();
for(i=0;i<m-1;i++)
d[n+i]=0;
r=new int[m+n];
for(i=0;i<m;i++)
r[i]=d[i];
z=new int[m];
76
for(i=0;i<m;i++)
z[i]=0;
for(i=0;i<n;i++)
{
k=0;
msb=r[i];
for(j=i;j<m+i;j++)
{
if(msb==0)
r[j]=xor(r[j],z[k]);
else
r[j]=xor(r[j],g[k]);
k++;
}
r[m+i]=d[m+i];
}
System.out.print("The code bits added are : ");
for(i=n;i<n+m-1;i++)
{
d[i]=r[i];
System.out.print(d[i]);
}
System.out.print("\nThe code data is : ");
for(i=0;i<n+m-1;i++)
{
System.out.print(d[i]);
}
}
public static int xor(int x,int y)
{
if(x==y)
return(0);
else
return(1);
}
}
77
OUTPUT:
RESULT:
Thus the java program to implement Cyclic Redundancy check was done and output was
verified.
INFERENCE:
78