Professional Documents
Culture Documents
PROGRAM:
import java.util.*;
try
while(scan.hasNextLine())
System.out.println(scan.nextLine());
System.out.println("error"+ex);
P1.Ping(args[0]);
OUTPUT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
import java.util.*;
try
while(scan.hasNextLine())
System.out.println(scan.nextLine());
System.out.println("error"+ex);
p.trace(args[0]);
OUTPUT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
import java.io.*;
import java.net.*;
InetAddress add=InetAddress.getByName("www.google.com");
boolean flag=true;
out.println("GET / HTTP/1.1");
out.println("HOST:www.google.com:80");
out.println("Connection:close");
out.println();
boolean loop=true;
while(loop)
if(in.ready())
int i=0;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
while(i!=-1)
i=in.read();
sb.append((char)i);
loop=false;
System.out.println(sb.toString());
s.close();
OUTPUT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
SERVER PROGRAM:
import java.net.*;
import java.io.*;
ServerSocket s=null;
String line;
DataInputStream is=null,is1=null;
PrintStream os=null;
Socket c=null;
try
s=new ServerSocket(99);
catch(IOException e)
System.out.println(e);
try
{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
c=s.accept();
is=new DataInputStream(c.getInputStream());
is1=new DataInputStream(System.in);
os=new PrintStream(c.getOutputStream());
do
line=is.readLine();
System.out.println("Client"+line);
System.out.println("Server");
line=is1.readLine();
os.println(line);
while(line.equalsIgnoreCase("quit")==false);
is.close();
os.close();
catch(IOException e)
System.out.println(e);
CLIENT PROGRAM:
import java.net.*;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
import java.io.*;
Socket c=null;
String line;
DataInputStream is,is1;
PrintStream os;
try
InetAddress ia = InetAddress.getLocalHost();
c=new Socket(ia,99);
catch(IOException e)
System.out.println(e);
try
os=new PrintStream(c.getOutputStream());
is=new DataInputStream(System.in);
is1=new DataInputStream(c.getInputStream());
while(true)
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
System.out.println("Client");
line=is.readLine();
os.println(line);
System.out.println("Server"+is1.readLine());
catch(IOException e)
System.out.println("Socket closed");
}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
OUTPUT:
SERVER:
CLIENT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
SERVER PROGRAM:
import java.io.*;
import java.net.*;
Socket sock=sersock.accept();
InputStream istream=sock.getInputStream();
String receivemessage,sendmessage;
while(true)
if((receivemessage=receivedread.readLine())!=null)
System.out.println(receivemessage);
}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
sendmessage=sendRead.readLine();
pwrite.println(sendmessage);
System.out.flush();
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
InputStream istream=sock.getInputStream();
String receivemessage,sendmessage;
while(true)
sendmessage=sendRead.readLine();
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
pwrite.println(sendmessage);
System.out.flush();
if((receivemessage=receivedread.readLine())!=null)
System.out.println(receivemessage);
OUTPUT:
SERVER:
CLIENT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
SERVER PROGRAM:
import java.net.*;
import java.io.*;
Socket sock=sersock.accept();
System.out.println("Connection is Successful");
InputStream istream=sock.getInputStream();
String fname=fileRead.readLine();
OutputStream ostream=sock.getOutputStream();
String str;
while((str=contentRead.readLine())!=null)
pwrite.println(str);
}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
sock.close();
sersock.close();
pwrite.close();
fileRead.close();
contentRead.close();
CLIENT PROGRAM:
import java.net.*;
import java.io.*;
String fname=keyRead.readLine();
OutputStream ostream=sock.getOutputStream();
pwrite.println(fname);
InputStream istream=sock.getInputStream();
String str;
while((str=socketRead.readLine())!=null)
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
System.out.println(str);
pwrite.close();
socketRead.close();
keyRead.close();
OUTPUT:
SERVER:
CLIENT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
SERVER PROGRAM:
import java.io.*;
import java.net.*;
str = str.trim();
for(int i=0;i<array.length;i++)
if(array[i].equals(str)) return i;
return -1;
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"};
while(true){
serversocket.receive(recvpack);
int port=recvpack.getPort();
String capsent;
if(indexOf(hosts,sen)!=-1)
senddata=capsent.getBytes();
serversocket.send(pack);
serversocket.close();
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
int portaddr=1362;
InetAddress ipaddress;
if(arg.length==0)
ipaddress= InetAddress.getLocalHost();
else
ipaddress=InetAddress.getByName(arg[0]);
senddata1=sentence.getBytes();
clientsocket.send(pack);
clientsocket.receive(recvpack);
System.out.println("Ip address"+modified);
clientsocket.close();
}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
OUTPUT:
SERVER:
CLIENT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
SERVER PROGRAM:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
try
Socket obj1=obj.accept();
while(true)
String str=din.readLine();
String ip[]={"172.16.27.99","172.16.27.3","172.16.27.4"};
String
mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};
for(int i=0;i<ip.length;i++)
{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
if(str.equals(ip[i]))
dout.writeBytes(mac[i]+'\n');
break;
obj.close();
catch(Exception e)
System.out.println(e);
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
try
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
s.close();
catch (Exception e)
System.out.println(e);
}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
OUTPUT:
SERVER:
CLIENT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
SERVER PROGRAM:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverarp
try
while(true)
server.receive(receiver);
String s = str.trim();
String ip[]={"165.165.80.80","165.165.79.1","192.168.7.3"};
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
String mac[]={"07:01:02:01:2C:4B","4A:30:10:21:10:1A","47:20:1B:2E:08:EE"};
for(int i=0;i<ip.length;i++)
if(s.equals(mac[i]))
sendbyte = ip[i].getBytes();
server.send(sender);
break;
break;
catch(Exception e)
System.out.println(e);
CLIENT PROGRAM:
import java.io.*;
import java.net.*;
import java.util.*;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
class Clientrarp
try
InetAddress addr=InetAddress.getByName("localhost");
String str=in.readLine();
sendbyte=str.getBytes();
client.send(sender);
client.receive(receiver);
client.close();
catch(Exception e)
{
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
System.out.println(e);
OUTPUT:
SERVER:
CLIENT:
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
NS2 SIMULATOR:
A simulator is a device, software or system which behaves or operates like a given system when
provided with a set of controlled inputs. The need for simulators is:
Provide users with practical feedback such as accuracy, efficiency, cost, etc., when designing
real world systems.
Permit system designers to study at several different levels of abstraction.
Simulation can give results that are not experimentally measurable with our current level of
technology.
Simulations take the building/rebuilding phase out of the loop by using the model already created
in the design phase.
Effective means for teaching or demonstrating concepts to students.
A few popular network simulators are NS-2, OPNET, GLOMOSIM, etc. Network Simulator NS2.
NS2 is an object-oriented, discrete event driven network simulator developed at UC Berkley written in
C++ and OTcl. NS is primarily useful for simulating local and wide area networks. NS2 is an
opensource simulation tool that primarily runs on Linux (cygwin for Windows). The features of NS2 are
How to start:
First of all, you need to create a simulator object. This is done with the command Now we open a file for
writing that is going to be used for the nam trace data.
The first line opens the file 'out.nam' for writing and gives it the file handle 'nf'. In thesecond line we tell
the simulator object that we created above to write all simulation data that is going to be relevant for
nam into this file.The next step is to add a 'finish' procedure that closes the trace file and starts nam.
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
proc finish {} {
global ns nf
$ns flush-trace
close $nf
, The next line tells the simulator object to execute the 'finish' procedure after 5.0 seconds of simulation
time.
ns provides you with a very simple way to schedule events with the 'at' command. The last line finally
starts the simulation.
$ns run
We can actually save the file now and try to run it with 'ns example1.tcl'. We are going to get an error
message like 'nam: empty trace file out.nam' though, because until now we haven't defined any objects
(nodes, links, etc.) or events.
proc finish {} {
global ns nf
$ns flush-trace
close $nf
exit 0
#Call the finish procedure after 5 seconds simulation time $ns at 5.0 "finish"
$ns run
A new node object is created with the command '$ns node'. The above code creates two nodes and
assigns them to the handles 'n0' and 'n1'. The next line connects the two nodes.
This line tells the simulator object to connect the nodes n0 and n1 with a duplex link with the bandwidth
1Megabit, a delay of 10ms and a DropTail queue. Now you can save your file and start the script with
'ns example1.tcl'. nam will be started automatically and you should see an output that resembles the
picture below.
This command creates an unidirectional link between node1 and node2 with specified bandwidth (BW)
and delay characteristics. The link uses a queue type of <qtype> and depending on the queue type
different arguments are passed through <args>.
This creates a bi-directional link between node1 and node2. This procedure essentially creates a duplex-
link from two simplex links, one from node1 to node2 and the other from node2 to node1. The syntax
for duplexlink is same as that of simplex-link described above.
This is used to set attributes for a simplex link. The attributes may be the orientation, color, label, or
queue-position.
This command is used to set link attributes (like orientation of the links, color, label, or queue-position)
for duplex links.
Sending data:
The next step is to send some data from node n0 to node n1. In ns, data is always being sent from one
'agent' to another. So the next step is to create an agent object that sends data from node n0, and another
agent object that receives the data on node n1.
These lines create a UDP agent and attach it to the node n0, then attach a CBR traffic generator to the
UDP agent. CBR stands for 'constant bit rate'. Line 7 and 8 should be self-explaining. The packet Size is
being set to 500 bytes and a packet will be sent every 0.005 seconds (i.e. 200 packets per second). The
next lines create a Null agent which acts as traffic sink and attach it to node n1.
Now the two agents have to be connected with each other. $ns connect $udp0 $null0 And now we have
to tell the CBR agent when to send data and when to stop sending.
This code should be self-explaining again. Now you can save the file and start the simulation again.
When you click on the 'play' button in the nam window, you will see that after 0.5 simulation
seconds,node 0 starts sending data packets to node 1. You might want to slow nam down then with the
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
'Step' slider. Now you start some experiments with nam and the Tcl script. You can click on any packet
in the nam window to monitor it, and you can also click directly on the link to get some graphs with
statistics.Try to change the 'packetsize_' and 'interval_' parameters in the Tcl script to see what happens.
Agents
Agents represent endpoints where network-layer packets are constructed or consumed, and are used in
the implementation of protocols at various layers.
Topology
You will always have to create a simulator object, you will always have to start the simulation with the
same command, and if you want to run nam automatically, you will always have to open a trace file,
initialize it, and define a procedure which closes it and starts nam.
Now insert the following lines into the code to create four nodes.
The following piece of Tcl code creates three duplex links between the nodes.
You can save and start the script now. You might notice that the topology looks a bit awkward in nam.
You can hit the 'relayout' button to make it look better, but it would be nice to have some more control
over the layout. Add the next three lines to your Tcl script and start it again.
After successful installation, path setting and validation, execute NS2 programs.
$ ns filename.tcl
RESULT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PROGRAM:
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exit 0 }
$ns run
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT:
PROGRAM:
proc finish { } {
global ns nr nf
$ns flush-trace
close $nf
close $nr
exit 0
$ns run
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT:
PROGRAM:
$ns1 rtproto DV
proc finish { } {
$ns1 flush-trace
close $nf1
close $nr1
exit 0 }
$ns1 run
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT:
PROGRAM:
$ns rtproto LS
$ns namtrace
all $nf
$ns trace
all $f0
proc finish {}
global ns f0 nf
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
close $f0
close $nf
exit 0
$ns attach
$cbr0 attach
agent $udp0
$ns attach
$ns con
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
$ns rtmodel
$ns rtmodel
$ns run
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT:
PROGRAM:
proc finish {} {
$ns flush-trace
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
close $file1
close $file2
exit 0
$ns rtproto DV
$ns run
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT:
PROGRAM:
# Create scheduler
# Turn on Tracing
# Create nodes
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
# Create links
set mproto DM
# Create receivers
# Schedule events
# Post-processing
proc finish {} {
global ns tf
$ns flush-trace
close $tf
exit 0
# Animation rate
$ns run
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT:
PROGRAM:
import java.io.*;
class crc_gen
InputStreamReader(System.in));
int[] data;
int[] div;
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
int[] divisor;
int[] rem;
int[] crc;
data_bits=Integer.parseInt(br.readLine());
data=new int[data_bits];
data[i]=Integer.parseInt(br.readLine());
divisor_bits=Integer.parseInt(br.readLine());
divisor=new int[divisor_bits];
divisor[i]=Integer.parseInt(br.readLine());
tot_length=data_bits+divisor_bits-1;
div=new int[tot_length];
rem=new int[tot_length];
crc=new int[tot_length];
for(int i=0;i<data.length;i++)
div[i]=data[i];
System.out.print(div[i]);
System.out.println();
rem[j] = div[j];
crc[i]=(div[i]^rem[i]);
System.out.println();
for(int i=0;i<crc.length;i++)
System.out.print(crc[i]);
/*-------------------ERROR DETECTION---------------------*/
System.out.println();
crc[i]=Integer.parseInt(br.readLine());
rem[j] = crc[j];
if(rem[i]!=0)
System.out.println("Error");
break;
if(i==rem.length-1)
System.out.println("No Error");
int cur=0;
while(true)
for(int i=0;i<divisor.length;i++)
rem[cur+i]=(rem[cur+i]^divisor[i]);
cur++;
if((rem.length-cur)<divisor.length)
break;
return rem;
}
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
OUTPUT:
PANIMALAR ENGINEERING COLLEGE
DEPARTMENT OF COMPUTER SCIENCE AND BUSINESS SYSTEMS
REG.NO: 211422244178
RESULT: