Professional Documents
Culture Documents
CN PRACTICAL Dhiraj 2820243
CN PRACTICAL Dhiraj 2820243
Samalkha, (Haryana)
Computer Science & Engineering Department
Computer Network
Lab
PC-CS- 308LA
Submitted to: Submitted by:
Mr. Kunar Uppal DHIRAJ KUMAR
(Assistant Prof.) ROLL NO. 2820243
CSE Department B.tech CSE 6th SEM
A
ff
il
ia
te
d
t
o
STEP 1: Firstly, we have to take two routers and then connect with each other
by using connection wire and then take no. of pc’s and connect them to the
switches separately as shown below.
STEP2:Now click on switch0 and switch 1 open CLI(Command Line Interface)
In the above Picture we have given 192.168.1.1 in the IP address and then we
click on Subnet Mask it will automatically fill its value with 255.255.255.0.
Now same process will be done for remaining PC for giving them IP Addresses.
STEP 4: Now try to transfer packets from one pc to another through switches.
The above picture shows the information of packet which is being transfers.
STEP 5: Hence by doing above steps we create a communication connection
between switches.
PRACTICAL-2-
STEP2-Set the hostnames according to the network diagram (R1 and R2) by
using CLI and Set the enable password on each router to 'cisco.
STEP 2-Set the hostname of each router according to the network diagram (R1
and R2) and Set the enable password of each router to 'cisco'.
Now, Set the enable secret of each router to 'ccna'
STEP 3-Exit back (by using exit command) to exec mode and try to enter
privileged exec mode. Which password do you have to use?
STEP 4- Enable password encryption on the router and view the running
configuration. What has changed?
STEP 5- Save the configuration and reload the router to confirm.
STEP 2- Use the console connection to configure the router from PC1. Change
the hostname to R1.
In the above Picture firstly, we have to use console password ccna and then if
we want to enter into the privileged-exec mode we have to input password
cisco.
STEP 4- Enable password encryption on R1 Verify by checking the running
configuration, and then save your configurations.
Now, Save your configurations.
PRACTICAL- 5
Aim: To write a java program for simulating ARP protocols using TCP
ALGORITHM:
Client
4. Send this IP address to server. 5. Server returns the MAC address to client.
Server
3. Server maintains the table in which IP and corresponding MAC addresses are stored.
5. Map the IP address with its MAC address and return the MAC address to client.
Program
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientarp
try
DataOutputStream dout=new
DataOutputStream(clsct.getOutputStream());
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
clsct.close();
catch (Exception e)
System.out.println(e);
Server:
import java.io.*;
import
java.net.*;
import
java.util.*;
class Serverarp
try
ServerSocket obj=new
ServerSocket(5604);
Socket obj1=obj.accept();
while(true)
DataOutputStream dout=new
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<ip.length;i++)
if(str.equals(ip[i]))
dout.writeBytes(mac[i]+'\n');
break;
}
obj.close();
catch(Exception e)
System.out.println(e);
}
PRACTICAL-6
Aim: To write a java program for simulating RARP protocols using UDP
ALGORITHM
Client
Server
2. Server maintains the table in which IP and corresponding MAC addresses are stored.
4. Map the IP address with its MAC address and return the IP address to client.
Program
Client
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
try
InetAddress addr=InetAddress.getByName("127.0.0.1");
client.send(sender);
client.receive(receiver);
client.close();
catch(Exception e)
System.out.println(e);
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
try
while(true)
server.receive(receiver);
String s=str.trim();
InetAddress addr=receiver.getAddress();
int port=receiver.getPort();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
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);
}
Output
Practical-7
Aim: To implement a Simple Calculator using TCP in Java.
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
InetAddress ip = InetAddress.getLocalHost();
while (true)
if (inp.equals("bye"))
break;
dos.writeUTF(inp);
System.out.println("Answer=" + ans);
}
Output
5*6
Answer=30
5+6
Answer=11
9/3
Answer=3
Server-Side Programming
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.StringTokenizer;
{
// Step 1: Establish the socket connection.
Socket s = ss.accept();
while (true)
if(input.equals("bye"))
break;
int result;
// operation
if (operation.equals("+"))
else if (operation.equals("-"))
else if (operation.equals("*"))
else
Output:
Equation received:-5 * 6
Equation received:-5 + 6
Equation received:-9 / 3
Practical-8
Aim: To simulate a sliding window protocol that uses Go Back N ARQ.
/*Server Program*/
import java.net.*;
import java.io.*;
import java.util.*;
System.out.println(“Server established.”);
Socket client=server.accept();
int x=(Integer)ois.readObject();
int k=(Integer)ois.readObject();
int j=0;
int i=(Integer)ois.readObject();
boolean flag=true;
int mod=r.nextInt(6);
while(mod==1||mod==0)
mod=r.nextInt(6);
while(true)
int c=k;
for(int h=0;h<=x;h++)
System.out.print(“|”+c+”|”);
c=(c+1)%x;
System.out.println();
System.out.println();
if(k==j)
j++;
System.out.println();
else
System.out.println();
flag=!flag;
j–;
}
else if(k==j-1)
oos.writeObject(k);
System.out.println(“Acknowledgement sent”);
System.out.println();
if(j%mod==0)
flag=!flag;
k=(Integer)ois.readObject();
if(k==-1)
break;
i=(Integer)ois.readObject();
oos.writeObject(-1);
/*Client Program*/
import java.util.*;
import java.net.*;
import java.io.*;
int m=Integer.parseInt(br.readLine());
int x=(int)((Math.pow(2,m))-1);
int count=Integer.parseInt(br.readLine());
int h=0;
for(int i=0;i<count;i++)
data[i]=Integer.parseInt(br.readLine());
h=(h+1)%x;
boolean flag=false;
listener=new GoBackNListener(ois,x);
listener.t.start();
int strt=0;
h=0;
oos.writeObject(x);
do
int c=h;
for(int i=h;i<count;i++)
System.out.print(“|”+c+”|”);
c=(c+1)%x;
System.out.println();
System.out.println();
h=strt;
for(int i=strt;i<x;i++)
System.out.println(“Sending frame:”+h);
h=(h+1)%x;
System.out.println();
oos.writeObject(i);
oos.writeObject(data[i]);
Thread.sleep(100);
listener.t.join(3500);
if(listener.reply!=x-1)
{
System.out.println(“No reply from server in 3.5 seconds. Resending data from frame
no ” + (listener.reply+1));
System.out.println();
strt=listener.reply+1;
flag=false;
else
flag=true;
}while(!flag);
oos.writeObject(-1);
Thread t;
ObjectInputStream ois;
int reply,x;
GoBackNListener(ObjectInputStream o,int i)
t=new Thread(this);
ois=o;
reply=-2;
x=i;
@Override
try
int temp=0;
while(reply!=-1)
reply=(Integer)ois.readObject();
reply=temp;
if(reply!=-1)
temp=reply;
System.out.println();
reply=temp;
catch(Exception e)
}
}
/*Client Output
|0||1||2||3||4|
Sending frame:0
Sending frame:1
Sending frame:2
Sending frame:3
Sending frame:4
Sending frame:5
*/
/*Server Output
Server established.
|0||1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||
20||21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||
37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||
54||55||56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||
71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||
88||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||
104||105||106||107||108||109||110||111||112||113||114||115||116||117||
118||119||120||121||122||123||124||125||126||0|
Frame 0 recieved
Data:0
Acknowledgement sent
|1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||
21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||
38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||
55||56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||
72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||
89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||
105||106||107||108||109||110||111||112||113||114||115||116||117||118||
119||120||121||122||123||124||125||126||0||1|
Frame 1 recieved
Data:1
|2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||
21||22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||
38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||
55||56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||
72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||
89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||
105||106||107||108||109||110||111||112||113||114||115||116||117||118||
119||120||121||122||123||124||125||126||0||1||2|
Expected farme:1
Recieved frame no :2
|3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||
22||23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||38||
39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||
56||57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||72||
73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||
90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||
106||107||108||109||110||111||112||113||114||115||116||117||118||119||
120||121||122||123||124||125||126||0||1||2||3|
Expected farme:1
Recieved frame no :3
|4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||
23||24||25||26||27||28||29||30||31||32||33||34||35||36||37||38||39||
40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||
57||58||59||60||61||62||63||64||65||66||67||68||69||70||71||72||73||
74||75||76||77||78||79||80||81||82||83||84||85||86||87||88||89||90||
91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||
107||108||109||110||111||112||113||114||115||116||117||118||119||120||
121||122||123||124||125||126||0||1||2||3||4|
Expected farme:1
Recieved frame no :4
*/