CN File
CN File
CN File
Of
(KCS-653)
(2022-2023)
2.
Configuration of the router, hub,
switch etc. (using real devices or
simulators)
Brief Theory:
RJ 45- Registered Jack 45 (RJ45) is a standard type of physical connector for network cables. RJ45
connectors are most commonly seen with Ethernet cables and networks. Modern Ethernet cables feature
small plastic plugs on each end that are inserted into the RJ45 jacks of Ethernet devices.
CAT-6 Cable- Category 6 Cable (Cat 6), is a standardized twisted pair cable for Ethernet and other
network physical layers.
Crimping Tool- A crimping tool is a device used to conjoin two pieces of metal by deforming one or
both of them in a way that causes them to hold each other.
Procedure:
To do these practical following steps should be done:
Step 1- Start by stripping off about 2 inches of the plastic jacket off the end of the cable. Be very careful
at this point, as to not nick or cut into the wires, which are inside. Doing so could alter the characteristics
of your cable or even worse render it useless. Check the wires, one more time for nicks or cuts. If there
are any, just whack the whole end off, and start over.
Step 2- Spread the wires apart, but be sure to hold onto the base of the jacket with your other hand. You
do not want the wires to become untwisted down inside the jacket. Category 5 cable must only have 1/2
of an inch of 'untwisted' wire at the end; otherwise, it will be 'out of spec'. At this point, you obviously
have ALOT more than 1/2 of an inch of un-twisted wire.
Step 3- You have 2 end jacks, which must be installed on your cable. If you are using a pre-made cable,
with one of the ends whacked off, you only have one end to install - the crossed-over end. Below are two
diagrams, which show how you need to arrange the cables for each type of cable end. Decide at this point
which end you are making and examine the associated picture below.
Figure 1.4: Color coding sequence for RJ45 connectors at both ends in straight-through wired
connection
Result- Configuration of networking hardware like RJ-45 connector, CAT-6 cable, crimping
tool, etc. is learned.
Experiment-2
Objective: Configuration of the router, hub, switch etc. (using real devices or simulators)
Procedure:
Step 1- Open Cisco packet Tracer Software and choose Generic Hub on the workspace.
Step 1- Open Cisco packet Tracer Software and choose Generic Switch on the workspace.
Configuration of Router
Modes of Router
3. Global Configuration Mode to Fast Ethernet Interface Mode: Router (config)# interface
FastEthernet 0/0
Step 3: Now click on each end device and enter an IP address such as 10.0.0.1 and label the device
with the corresponding IP address using the text tool available in the cisco packet tracer. Ensure
that the router should connect two different networks.
Figure 2.11:IP configuration in end devices
Step 4: Double click router and type router commands to configure the router at interface fa0/0
and fa0/1
Router>enable
Router#configure terminal
Router(config)#hostname R1
Router(config)#interface fastethernet 0/0
Router(config-if )# 10.0.0.1 255.0.0.0
Router(config-if )# no shut down
Step 6- Now click on simulation and click on AutoPlay to see the effect.
Result:
Configuration of the router, hub, and switch is performed.
Experiment-3
Objective: To implement the stop-and-wait protocol using Java programming language.
Procedure:
Sender
Step 1: sequence 0
Step 2: Accept new packet and assign a sequence to it.
Step 3: Send packet sequence with sequence number sequence.
Step 4: Set timer for recently sent packets.
Step 5: If error-free acknowledgment from the receiver and NextFrameExpected -> sequence then
sequence NextFrameExpected.
Step 6: If time out then go to step3.
Step 7: Stop.
Receiver
Step 1: Start.
Step 2: NextFrameExpected 0, repeat steps 3 forever.
Step 3: If error-free frame received and sequence= NextFrameExpected, then pass packet to higher
layer and NextFrameExpected NextFrameExpected+1(modulo 2).
Step 4: Stop.
Code:
Sender.java
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",2005);
sequence=0;
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();
}
catch(Exception e){}
}}
public static void main(String args[]){
Sender s=new Sender();
s.run();
}}
Receiver.java
import java.io.*;
import java.net.*;
public class Receiver{
ServerSocket reciever;
Socket connection=null;
ObjectOutputStream out;
ObjectInputStream in;
String packet,ack,data="";
int i=0,sequence=0;
Receiver(){}
public void run(){
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
reciever = new ServerSocket(2005,10);
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{
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){}
}}
Output:
client class
server class
Sliding window protocols are used to deliver in-order packets in Transmission Control Protocol (TCP)
and Data link layer and it is also a feature of packet-based data transmission protocols.
Detail:
The socket is an endpoint of the two-way communication link between two programs running on the
same network and the programs communicate with each other using the port running port numbers on
the network. Here, the client and server are the two programs using the socket for transferring data.
Advantage:
• Sliding window protocol is efficient than the Stop and Wait protocol.
• Sliding window protocol sends multiple frames and retransmits damaged frames.
Program:
SERVER:
import java.io.*;
import java.net.*;
public class server {
try
{
ServerSocket ss1;
ss1 = new ServerSocket(9000);
Socket s =ss1.accept();
DataInputStream dd= new DataInputStream(s.getInputStream());
String sss1 = dd.readUTF();
System.out.println(sss1);
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
--------------------------------
CLIENT:
import java.io.*;
import java.net.*;
public class client {
public static void main(String args[])
{
String h="localhost";
int p=9000;
Try
{
Socket s1;
s1= new Socket(h,p);
DataOutputStream d = new DataOutputStream(s1.getOutputStream());
d.writeUTF("Start server :");
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
Output:
Server class
Client class
Experiment-4
Brief Theory:
Java programming is used for communication between the applications running on different JRE.
Socket and ServerSocket classes are used for connection-oriented socket programming and
DatagramSocket and DatagramPacket classes are used for connection-less socket programming.
Here, we are going to make one-way client and server communication. In this application, the client
sends a message to the server, the server reads the message and prints it. Here, two classes are being
used: Socket and ServerSocket. The Socket class is used to communicate client and server. Through
this class, we can read and write messages. The ServerSocket class is used on the server side. The
accept() method of ServerSocket class blocks the console until the client is connected. After the
successful connection of the client, it returns the instance of Socket at the server side.
Socket class
A socket is simply an endpoint for communications between the machines. The Socket class can be
used to create a socket.
Important methods:
Method Description
1) public InputStream getInputStream() returns the InputStream attached with this socket.
2) public OutputStream getOutputStream() returns the OutputStream attached with this socket.
ServerSocket class
The ServerSocket class can be used to create a server socket. This object is used to establish
communication with the clients.
Important methods:
Method Description
1) public Socket accept() returns the socket and establish a connection between server and
client.
Creating Server:
To create the server application, we need to create the instance of ServerSocket class. Here, we are
using the 6666 port number for communication between the client and server. You may also choose
any other port number. The accept() method waits for the client. If clients connect with the given port
number, it returns an instance of Socket.
To create the client application, we need to create the instance of Socket class. Here, we need to pass
the IP address or hostname of the Server and a port number. Here, we are using "localhost" because
our server is running on same system.
Let's see a simple Java socket programming where the client sends a text and the server receives and
prints it.
File: MyServer.java
import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
}
}
File: MyClient.java
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
}
}
Experiment-5
Objective:
To write a Java program for the socket for HTTP for web page upload and download.
Algorithm:
1. Start the program.
2. Get the frame size from the user
5. If your frames reach the server it will send an ACK signal to the client otherwise it will send
NACK signal to the client.
Program:
Client code
import javax.swing.*;
import java.net.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.*;
dos.write(bytes, 0, bytes.length);
System.out.println("Image sent to server. ");
dos.close();
out.close();
soc.close();
}
}
Server code
import java.net.*;
import java.io.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
class Server {
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();
f.pack();
f.setVisible(true);
}
}
Output: Client-Side Output
When you execute the client code, the following output appears on the client side −
Server-Side Output
When you execute the server code, the following output appears on server side −
After receiving the image, the server displays the image as shown below −