EX - NO.1 Aim: To Learn and Use Network Commands
EX - NO.1 Aim: To Learn and Use Network Commands
EX - NO.1 Aim: To Learn and Use Network Commands
1 NETWORK COMMANDS
Aim
To learn and use network commands .
COMMANDS
1.netstat
2. ipconfig
3.nslookup
RESULT
Thus the network commands was leaned and used successfully.
Ex.no.2 CREATE A SOCKET FOR HTTP FOR WEB PAGE
UPLOAD AND DOWNLOAD.
AIM:
To write a java program for socket for HTTP for web page upload and
download.
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
/*http 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 f = new JFrame("Server");
ImageIcon icon = new ImageIcon(bImage);
JLabel l = new JLabel(); l.setIcon(icon);
f.add(l); f.pack();
f.setVisible(true);
}}
/*httpClient*/
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("Desert.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos); 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(); } }
OUTPUT:
SERVER:
C:\Java\jdk1.8.0_77\bin>javac Server.java
C:\Java\jdk1.8.0_77\bin>java Server
Client connected.
CLIENT:
C:\Java\jdk1.8.0_77\bin>javac Client.java
C:\Java\jdk1.8.0_77\bin>java Client
Client is running.
RESULT
Thus the program was implementing to socket for HTTP for web page
upload and download.
Ex.no.3a APPLICATIONS USING TCP SOCKETS
ALGORITHM
1.Start the program.
2.Get the frame size from the user
3.To create the framebased 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
/*EchoServer*/
import java.io.*;
import java.net.*;
public class EchoServer
{
public EchoServer(int portnum)
{
try
{
server = new ServerSocket(portnum);
}
catch (Exception err)
{
System.out.println(err);
}
}
public void serve()
{
try
{
while (true)
{
Socket client = server.accept();
BufferedReader r = new BufferedReader(new
InputStreamReader(client.getInputStream()));
PrintWriter w = new PrintWriter(client.getOutputStream(), true);
w.println("Welcome to the Java EchoServer. Type 'bye' to close.");
String line;
do
{
line = r.readLine();
if ( line != null )
w.println("Got: "+ line);
}
while ( !line.trim().equals("bye") );
client.close();
}
}
catch (Exception err)
{
System.err.println(err);
}
}
public static void main(String[] args)
{
EchoServer s = new EchoServer(9999);
s.serve();
}
private ServerSocket server;
}
/*EchoClient*/
import java.io.*;
import java.net.*;
public class EchoClient
{
public static void main(String[] args)
{
try
{
Socket s = new Socket("127.0.0.1", 9999);
BufferedReader r = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter w = new PrintWriter(s.getOutputStream(), true);
BufferedReader con = new BufferedReader(new
InputStreamReader(System.in));
String line;
do
{
line = r.readLine();
if ( line != null )
System.out.println(line);
line = con.readLine();
w.println(line);
}
while ( !line.trim().equals("bye") );
}
catch (Exception err)
{
System.err.println(err);
}}}
OUTPUT:
SERVER:
C:\Java\jdk1.8.0_77\bin>javac EchoServer.java
C:\Java\jdk1.8.0_77\bin>java EchoServer
CLIENT:
C:\Java\jdk1.8.0_77\bin>javac EchoClient.java
C:\Java\jdk1.8.0_77\bin>java EchoClient
hai
Got: hai
bye
RESULT:
Thus, the java program on ECHO CLIENT AND SERVER USING UDP
Sockets is well executed.
Ex.no.3b APPLICATIONS USING TCP SOCKETS
CHAT
AIM
To write a java program for application using TCP Sockets Links
ALGORITHM
1.Start the program.
2.Get the frame size from the user
3.To create the framebased 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
/*chatTCPserver*/
import java.io.*;
import java.net.*;
class TCPserver
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
ds=new DatagramSocket(clientport);
System.out.println("press ctrl+c to quit the program");
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Client:" + psx);
System.out.println("Server:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new
DatagramPacket(buffer,str.length(),ia,serverport));
} }}
/*chat TCPClient*/
import java .io.*;
import java.net.*;
class TCPclient
{
public static DatagramSocket ds;
public static int clientport=789,serverport=790;
public static void main(String args[])throws Exception
{
byte buffer[]=new byte[1024];
ds=new DatagramSocket(serverport);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
System.out.println("server waiting");
InetAddress ia=InetAddress.getLocalHost();
while(true)
{
System.out.println("Client:");
String str=dis.readLine();
if(str.equals("end"))
break;
buffer=str.getBytes();
ds.send(new DatagramPacket(buffer,str.length(),ia,clientport));
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
String psx=new String(p.getData(),0,p.getLength());
System.out.println("Server:" + psx);
}}}
OUTPUT:
SERVER SIDE:
C:\Java\jdk1.8.0_77\bin>javac TCPserver.java
C:\Java\jdk1.8.0_77\bin>java TCPserver
press ctrl+c to quit the program
Client:hai
Server:
how are you
Client:how are u
Server:
fine thanks
Client:fine thanks
Server:
end
C:\Java\jdk1.8.0_77\bin>
CLIENT SIDE:
C:\Java\jdk1.8.0_77\bin>javac TCPclient.java
C:\Java\jdk1.8.0_77\bin>java TCPclient
server waiting
Client:
hai
Server:how
Client:
how are u
Server:fine than
Client:
fine thanks
RESULT:
Thus, the java program on CHAT CLIENT AND SERVER USING UDP
Sockets is well executed.
Ex.no.3c APPLICATIONS USING TCP SOCKETS
FILE TRANSFER
AIM
To write a java program for application using TCP Sockets Links
ALGORITHM
1.Start the program.
2.Get the frame size from the user
3.To create the framebased 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
/*ftpserver*/
import java.io.*;
import java.net.*;
class ftpserver
{
public static void main(String args[])throws IOException
{
char ch[] = new char[35];
String str;
int i=0,j;
ServerSocket ss = new ServerSocket(5600);
Socket s = ss.accept();
BufferedReader in = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
String fname = in.readLine();
FileInputStream fin = new FileInputStream(fname);
while(true)
{
for(i=0;i<30;i++)
{
j=fin.read();
ch[i]=(char)j;
if(j==-1)
break;
}
str = new String(ch,0,i);
out.println(str);
if(i!=30)
break;
}
out.println("EOF");
in.close();
out.close();
s.close();
ss.close();
}
}
/*ftpclient*/
import java.io.*; import java.net.*;
class ftpclient
{
public static void main(String args[])throws Exception
{
BufferedReader in1 = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the hostname to connect:");
Socket s = new Socket(InetAddress.getByName(in1.readLine()),5600);
BufferedReader in2 = new BufferedReader(new
InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
System.out.println("Enter the source filename:");
out.println(in1.readLine());
System.out.println("Enter the destination filename:");
FileOutputStream fout = new FileOutputStream(in1.readLine());
String data; int i=0;
while(true)
{
data = in2.readLine();
if(data.equals("EOF"))
break; char ch[] = new char[35];
data.getChars(0,data.length(),ch,0);
for(i=0;i<data.length();i++)
fout.write((int)ch[i]);
}
in1.close(); in2.close(); out.close(); s.close();
fout.close();
}}
OUTPUT:
SERVER SIDE:
C:\Java\jdk1.8.0_77\bin>javac ftpserver.java
C:\Java\jdk1.8.0_77\bin>java ftpserver
CLIENT SIDE:
C:\Java\jdk1.8.0_77\bin>javac ftpclient.java
C:\Java\jdk1.8.0_77\bin>java ftpclient
Enter the hostname to connect:
localhost
Enter the source filename:
ex.txt
Enter the destination filename:
ex1.txt
C:\Java\jdk1.8.0_77\
RESULT:
AIM
To write a java program for DNS using UDP Sockets
ALGORITHM
PROGRAM
Udpdnsserver
import.java import java.io.*;
import java.net.*;
RESULT:
Thus, the java program for DNS using UDP Socket is well executed.
Ex.no.5a Write a code simulating ARP /RARP protocols
Aim:
To write a java program for simulating arp/rarp protocols
ALGORITHM:
server
1. Create a server socket and bind it to port.
2. Listen for new connection and when a connection arrives, accept it.
3. Send server‟s date and time to the client.
4. Read client‟s IP address sent by the client.
5. Display the client details.
6. Repeat steps 2-5 until the server is terminated.
7. Close all streams.
8. Close the server socket.
Client
1. Create a client socket and connect it to the server‟s port number.
2. Retrieve its own IP address using built-in function.
3. Send its address to the server.
4. Display the date & time sent by the server.
5. Close the input and output streams.
6. Close the client socket.
7. Stop.
PROGRAM
/*ServerARP*/
{
if(s.equals(mac[i]))
{
sendbyte=ip[i].getBytes();
DatagramPacket
sender=newDatagramPacket(sendbyte,sendbyte.length,addr,port);
server.send(sender);
break;
}
}
break;
}
}
catch(Exception e)
{
System.out.println(e);
}}}
/*ClientRARP*/
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp12
{
public static void main(String args[])
{
try
{
DatagramSocket client=new DatagramSocket();
InetAddress addr=InetAddress.getByName("127.0.0.1");
byte[] sendbyte=new byte[1024];
byte[] receivebyte=new byte[1024];
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the Physical address (MAC):")
String str=in.readLine(); sendbyte=str.getBytes();
DatagramPacket
sender=newDatagramPacket(sendbyte,sendbyte.length,addr,1309);
client.send(sender);
DatagramPacket receiver=new
DatagramPacket(receivebyte,receivebyte.length);
client.receive(receiver);
String s=new String(receiver.getData());
System.out.println("The Logical Address is(IP): "+s.trim());
client.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
I:\ex>java Serverrarp12
I:\ex>java Clientrarp12
Enter the Physical address
(MAC): 6A:08:AA:C2
The Logical Address is(IP): 165.165.80.80
RESULT:
Thus the program for implementing to display simulating ARP /RARP
protocols.
Ex.no.6 STUDY OF NETWORK SIMULATOR
(NS).AND SIMULATION OF
CONGESTION CONTROL ALGORITHMS
USING NS
AIM:
To Study of Network simulator (NS).and Simulation of Congestion
Control Algorithms using NS.
NET WORK SIMULATOR (NS2)
Ns overview
Ns programming: A Quick start
Case study I: A simple Wireless network
Case study II: Create a new agent in Ns
Ns overview
Ns Status
Periodical release (ns-2.26, Feb 2003)
Platform support
FreeBSD, Linux, Solaris, Windows and Mac
Ns unctionalities
Routing, Transportation, Traffic sources,Queuing disciplines, QoS
Wireless
Ad hoc routing, mobile IP, sensor-MAC Tracing, visualization and various
utilitie
NS(Network Simulators) Most of the commercial simulators are GUI driven,
while some network simulators are CLI driven. The network model /
configuration describes the state of the network (nodes,routers, switches, links)
and the events (data transmissions, packet error etc.). An important output of
simulations are the trace files. Trace files log every packet, every event that
occurred in the simulation and are used for analysis. Network simulators can
also provide other tools to facilitate visual analysis of trends and potential
trouble spots. Most network simulators use discrete event simulation, in which a
list of pending "events" is stored, and those events are processed in order, with
some events triggering future events-such as the event of the arrival of a packet
at one node triggering the event of the arrival of that packet at a downstream
node. Simulation of networks is a very complex task. For example, if
congestion is high, then estimation of the average occupancy is challenging
because of high variance. To estimate the likelihood of a buffer overflow in a
network, the time required for an accurate answer can beextremely large.
Specialized techniques such as "control variates" and "importance sampling"
have been developed to speed simulation.
Examples of network simulators
There are many both free/open-source and proprietary network simulators.
Examples of notable network simulation software are, ordered after how often
they are mentioned in research papers:
1. ns (open source)
2. OPNET (proprietary software)
3. NetSim (proprietary software)
Uses of network simulators
Network simulators serve a variety of needs. Compared to the cost and time
involved in setting up an entire test bed containing multiple networked
computers, routers and data links, network simulators are relatively fast and
inexpensive. They allow engineers, researchers to test scenarios that might be
particularly difficult or expensive to emulate using real hardware for instance,
simulating a scenario with several nodes or experimenting with a new protocol
in the network. Network simulators are particularly useful in allowing
researchers to test new networking protocols or changes to existing protocols in
a controlled and reproducible environment. A typical network simulator
encompasses a wide range of networking technologies and can help the users to
build complex networks from basic building blocks such as a variety of nodes
and links. With the help of simulators, one can design hierarchical networks
using various types of nodes like computers, hubs, bridges, routers, switches,
links, mobile units etc. Various types of Wide Area Network (WAN)
technologies like TCP, ATM, IP etc. and LocalArea Network (LAN)
technologies like Ethernet, token rings etc., can all be simulated with a typical
simulator and the user can test, analyze various standard results apart from
devising some novel protocol or strategy for routing etc. Network simulators are
also widely used to simulate battlefield networks in Network-centric warfare
There are a wide variety of network simulators, ranging from the very simple to
the very complex. Minimally, a network simulator must enable a user to
represent a network topology, specifying the nodes on the network, the links
between those nodes and the traffic between the nodes. More complicated
systems may allow the user to specify everything about the protocols used to
handle traffic in a network. Graphical applications allow users to easily
visualize the workings of their simulated environment. Text-based applications
may provide a less intuitive interface, but may permit more advanced forms of
customization.
Packet loss
occurs when one or more packets of data travelling across a computer network
fail to reach their destination. Packet loss is distinguished as one of the three
main error types encountered in digital communications; the other two being bit
errorand spurious packets caused due to noise. Packets can be lost in a network
because they may be dropped when a queue in the network node overflows. The
amount of packet loss during the steady state is another important property of a
congestion control scheme. The larger the value of packet loss, the more
difficult it is for transport layer protocols to maintain high bandwidths, the
sensitivity to loss of individual packets, as well as to frequency and patterns of
loss among longer packet sequences is strongly dependent on the application
itself.
Throughput
This is the main performance measure characteristic, and most widely used. In
communication networks, such as Ethernet or packet radio, throughput or
network throughput is the average rate of successful message delivery over a
communication channel. The throughput is usually measured in bits per second
(bit/s or bps), and sometimes in data packets per second or data packets per time
slot This measure how soon the receiver is able to get a certain amount of data
send by the sender. It is determined as the ratio of the total data received to the
end to end delay. Throughput is an important factor which directly impacts the
network performance
Delay
Delay is the time elapsed while a packet travels from one point e.g., source
premise or network ingress to destination premise or network degrees. The
larger the value of delay, the more difficult it is for transport layer protocols to
maintain high bandwidths. We will calculate end to end delay
Queue Length
A queuing system in networks can be described as packets arriving for service,
waiting for
service if it is not immediate, and if having waited for service, leaving the
system after being
served. Thus queue length is very important characteristic to determine that how
well the active queue management of the congestion control algorithm has been
working.
RESULT
Thus the study of Network simulator (NS2) was studied.
Ex.no.7 STUDY OF TCP/UDP PERFORMANCE USING
SIMULATION TOOL.
AIM:
To Study of tcp/udp performance using simulation tool.
RESULT
Thus the study of tcp/udp performance using simulation tool was studied.
Ex.no.8a DISTANCE VECTOR
Aim
PROGRAM
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
$ns rtproto DV
$ns run
RESULT
Thus the distance vector rounting algorithm was executed
successfully.
Ex.no.8b LINK STATE ROUTING ALGORITHM.
Aim
PROGRAM
ns [new Simulator]
proc finish {} {
global nf ns tr
$ns flush-trace
close $tr
exec nam out.nam &
exit 0
}
$ns rtproto LS
$ns run
RESULT
Thus the link state rounting algorithm was executed successfully.
Ex.no.9 PERFORMANCE EVALUATION OF ROUTING PROTOCOLS
USING SIMULATION TOOL
AIM:
To Study of performance evaluation of routing protocols using simulation tool
VANET ROUTING PROTOCOLS
There are many routing protocols available for VANET. Among them all we are
working with AODV and DSR for performance analysis.
A.Ad-hoc On demand Distance Vector (AODV)
It is purely On-Demand route acquisition routing protocol. It is better
protocol than DSDV network as the size of network may increase depending
on the number of vehicle nodes.
1) Path Discovery Process: In order to discover the path between source
and destination, a route request message (RREQ) is broadcasted to all the
neighbours in radio range who again continue to send the same to their
neighbours in there radio range, until the destination is reached. Every node
maintains two counters: sequence number and broadcast-id in order to maintain
loop-free and most recent route information. The broadcast-id is incremented
for every RREQ the source node initiates. If an intermediate node receives the
same copy of request, it discards it without routing it further. When a node
forwards the RREQ message, it records the address of the neighbour from
which it received the first copy of the broadcast packet, in order to maintain a
reverse path to the source node. The RREQ packet contains: the source
sequence number and the last destination sequence number know to the source.
The source sequence number is used to maintain information about reverse
route and destination sequence number tells about the actual distance to the final
node.
2) Route Maintenance: A source node sends a new moving request packet
RREQ to find a new route to the destination. But, if an intermediate node moves
from its place, its upstream neighbor noticed the move and sends a message
notification failure of the link to each of its active upstream neighbors to inform
them about the move to source nodes is achieved. After the detection process is
again initiated.
B. Dynamic Source Routing (DSR)
It is an On-Demand routing protocol in which the sequence of nodes
through which a packet needs to travel is calculated and maintained as an
information in packet header. Every mobile node in the network needs to
maintain a route cache where it caches source routes that it has learned. When a
packet is sent, the route-cache inside the node is compared with the actual route
needs to be covered.
1) Route Discovery: The source node broadcasts request-packets to all the
neighbours in the network containing the address of the destination node, and a
reply is sent back to the source node with the list of network-nodes through
which it should propagate in the process. Sender initiates the route record as a
list with a single element containing itself followed by the linking of its
neighbour in that route. A request packet also contains an identification number
called request-id, which is counter increased only when a new route request
packet is being sent by the source node. To make sure that no loops occur
during broadcast, the request is processed in the given order. A route reply is
obtained in DSR by two ways: Symmetric-links (bidirectional), in which the
backward route is followed again to catch the source node. Asymmetric-links
(unidirectional) needs to discover the route up to the source node in the same
manner as the forward route is discovered.
2) Route Maintenance: In the hop by hop acknowledgement at data link
layer allows the early detection and retransmission of lost or corrupt packets in
the data-link layer. If a transmission error occurs, a route error packet
containing the address of node detecting the error and the host address is sent
back to the sender. Whenever a node receives a route error packet, the hop in
error is removed from the route cache and all routes containing this hop are
truncated at that point. When the wireless transmission between two nodes
does not work equally well in both directions, and then end-to-end replies on
the application or transport layer may be used to indicate the status of the route
from one host to the other
RESULT
Thus Study of performance evaluation of routing protocols using
simulation tool was studied.
Ex.no.10 ERROR CORRECTION CODE (LIKE CRC).
AIM
To write a java program for CRC using java.
ALGORITHM
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];
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);
}
}
OUTPUT
Enter no. of data bits : 14
Enter no. of generator bits : 4
Enter data bits : 1
1
0
1
0
0
1
1
1
0
1
1
0
0
RESULT
Thus the cyclic redundancy check (error correction) algorithm was
executed successfully.