Network Programming Lab Manual - Exp 1-5
Network Programming Lab Manual - Exp 1-5
Define Network
A network consists of two or more computers that are linked in order to share resources (such as
printers and CDs), exchange files, or allow electronic communications. The computers on a
network may be linked through cables, telephone lines, radio waves, satellites, or infrared light
beams.
Networking Components:-
Computer networks components comprise both Hardware parts as well as the software parts
required for installing computer networks, both at organizations and at home. The hardware
components are the server, client, peer, transmission medium, and connecting devices. The
software components are operating system and protocols.
Components of Network.
Hardware Components:-
Servers: Servers are high-configuration computers that manage the resources of the network.
The network operating system is typically installed in the server and so they give user accesses to
the network resources. Servers can be of various kinds: file servers, database servers, print
servers etc.
Clients: − Clients are computers that request and receive service from the servers to access and
use the network resources.
Peers:- Peers are computers that provide as well as receive services from other peers in a
work group network.
Transmission Media:- Transmission media are the channels through which data is
transferred from one device to another in a network. Transmission media may be guided media
like coaxial cable, fiber optic cables etc; or maybe unguided media like microwaves, infra-red
wave etc.
Networking Devices:- Connecting devices act as middleware between networks or
computers, by binding the network media together. Some of the common connecting devices
are:
1. Routers
2. Hub
3. Switch
4. Bridge
5. Repeater
6. Gateway
Software Components:-
LAN Adapter:-
A LAN adapter is an expansion board that is used to connect a computer or computing
device to a network. LAN adapter is the most common and generic alternate name for a
Network Interface Card(NIC). Similar products, such as Wireless USB LAN Adapter rare
referred to as LAN adapters.
LAN ADAPTER
Functions of LAN Adapter:-
The computer and the card must communicate with each other so that they can proceed to
exchange information. In this way, the computer allocates part of its memory to cards
that have DMA (Direct memory access).The card interface indicates that another computer is
requesting data from the computer. The computer bus transfers the data from the computer
memory to the network card.
Networking Devices
Router:
Routers are
OSI model. They are responsible for receiving, analyzing, and forwarding data packets among the
connected computer networks. When a data packet arrives, the router inspects the destination
address, consults its routing tables to decide the optimal route and then transfers the packet along
this route.
A router examines a packet header's destination IP address and compares it against a routing
table to determine the packet's best next hop. Routing tables list directions for forwarding data to
particular network destinations, sometimes in the context of other variables, like cost. They
amount to an algorithmic set of rules that calculate the best way to transmit traffic toward any
given IP address. A routing table often specifies a default route, which the router uses whenever it
fails to find a better forwarding option for a given packet. For example, the typical home
office router directs all outbound traffic along a single default route to its internet service
provider (ISP) Routing tables can be static -- i.e., manually configured -- or dynamic. Dynamic
routers automatically updated their routing tables based on network activity, exchanging
information with other devices via routing protocols.
Hub:-
A Network Hub is one of the most commonly used networking devices can be easily
found on any small networks such as home or
office. Hub operates at the physical layer of OSI
model. It is the simplest networking device hence
has low cost. Basically, a hub is a repeater with
multiple ports. The function of a hub in
networking is similar to the repeater. It transfers
data in the form of binary bits and uses for
broadcasting data.
Working of Hubs:-When a host sends frames, the hub forwards the frames in all the ports. Hubs
do not separate the type of the frame, for example, whether the frame unicast should be either
multicast or broadcast. Hubs forward all the frames into all the ports. Although a hub s e n d s
the frames to all the ports, a computer accepts the ones, whose MAC match matches the
d e s t i n a t i o n MAC address field. The rest of the frames are discarded after receiving the
required information.
Switch:-
Diagram- Switch
Working of Switch:-Whenever a host sends a frame to any other host, then the source host is stored
with the port in the address table of the MAC address switch. A switch always stores the address of
the source in the table. Unless a host does send some data, its MAC address and port number will not
be stored in the table of the switch. Unless a host does send some data, its MAC address and port
number will not be stored in the table of the switch. When you initialize the switch, the switch
does not contain any information about any host and its address. In such a situation, when a host
frame sends, its MAC address is stored in the table but due to no destination information, the switch
sends the frame to all the hosts .When you initialize the switch, the switch does not contain any
information about any host and its address. In such a situation, when a host frame sends, its MAC
address is stored in the table but due to no destination information, the switch sends the frame to all
the hosts. As soon as the second host sends some data, its address also gets stored in the table. As
soon as the second host sends some data, its address also gets stored in the table.
Whenever a host sends the frames, the switch stores it if its address is not already present in the
table. Thus a switch creates its table. When all the hosts’ addresses and port numbers
come in the switch, the switch delivers the frame to all hosts only, delivering the same
host to the host for which the data has been sent.
Bridge:-
Bridge is termed as a network device which is helpful in filtering the data load of the traffic
by dividing it into segments or packets. They are used to lower the load of traffic on the LAN
and other networks. Bridges are passive devices, because there is no interaction between
bridged and the paths of bridging. Bridges operate on the second layer of the OSI model that is
the data link layer.
Working of Bridge:-
When various network segments are established at the data link layer of the OSI model,
we refer to it as bridge. However when the packets ofdata are transferred along a network ,
without locating the network addresses this process is termed as bridging. The process of
bridging is helpful in locating the addresses of unknown addresses to which it is viable to
send data. In bridging the data packets contain a header or a packet header which holds the
address to the intended device. Bridge can remember and recall the address of the devices
for further transmission. There are two kinds of bridging modes, the transparent bridging and the
source routing bridging. When the process of bridging occurs, it makes a bridging table along
side where it stores the MAC addresses of the various terminals. This table helps the
bridges to send the data packet to the exact location next time. However when a specific
address does not meet the contents of the bridging table, the data packet is forwarded
further ahead to every attached terminal in LAN except from the computer it is connected to.
This type of bridging is called transparent bridging. When the source computer presents
pathway information within the packet, this type of bridging is known as source route bridging.
It is most commonly used in used on Token Ring networks.
Repeater:-
A repeater is a network device that retransmits a received signal with more power and to an
extended geographical or topological network boundary than what would be capable with the
original signal repeater is implemented in computer networks to expand the coverage area of the
network, re propagate a weak or broken signal and or service remote nodes. Repeaters amplify
the received/input signal to a higher frequency domain so that it is reusable, scalable.
Diagram: Repeater
Working of Repeater:-
When an electrical signal is transmitted via a channel, it gets attenuated depending upon the
nature of the channel or the technology. This poses a limitation upon the length of the LAN or
coverage area of cellular networks. This problem is alleviated by installing repeaters at certain
intervals.
Repeaters amplifies the attenuated signal and then retransmits it. Digital repeaters can even
reconstruct signals distorted by transmission loss. So, repeaters are popularly incorporated to
connect between two LANs thus forming a large single LAN
Gateway:-
Working of Gateways
Ex.No. : 2 Use of Wireshark network tool
Running Wireshark When you run the Wireshark program, the Wireshark graphical user
interface shown in Figure below will be displayed. Initially, no data will be displayed in the
various windows.
The command menus are standard pulldown menus located at the top of the window. Of
interest to us now are the File and Capture menus. The File menu allows you to save
captured packet data or open a file containing previously captured packet data, and exit
the Wireshark application. The Capture menu allows you to begin packet capture.
The packet-listing window displays a one-line summary for each packet captured,
including the packet number (assigned by Wireshark; this is not a packet number
contained in any protocol’s header), the time at which the packet was captured, the
packet’s source and destination addresses, the protocol type, and protocol-specific
information contained in the packet. The packet listing can be sorted according to any of
these categories by clicking on a column name. The protocol type field lists the highest
level protocol that sent or received this packet, i.e., the protocol that is the source or
ultimate sink for this packet.
The packet-header details window provides details about the packet selected
(highlighted) in the packet listing window. (To select a packet in the packet listing
window, place the cursor over the packet’s one-line summary in the packet listing
window and click with the left mouse button.). These details include information about
the Ethernet frame (assuming the packet was sent/receiverd over an Ethernet interface)
and IP datagram that contains this packet. The amount of Ethernet and IP-layer detail
displayed can be expanded or minimized by clicking on the plus minus boxes to the left
of the Ethernet frame or IP datagram line in the packet details window. If the packet has
been carried over TCP or UDP, TCP or UDP details will also be displayed, which can
similarly be expanded or minimized. Finally, details about the highest level protocol that
sent or received this packet are also provided.
The packet-contents window displays the entire contents of the captured frame, in both
ASCII and hexadecimal format.
Towards the top of the Wireshark graphical user interface, is the packet display filter
field, into which a protocol name or other information can be entered in order to filter the
information displayed in the packet-listing window (and hence the packet-header and
packet-contents windows). In the example below, we’ll use the packet-display filter field
to have Wireshark hide (not display) packets except those that correspond to HTTP
messages.
Taking Wireshark for a Test Run The best way to learn about any new piece of software
is to try it out! We’ll assume that your computer is connected to the Internet via a wired
Ethernet interface. Do the following
1. Start up your favorite web browser, which will display your selected homepage.
2. Start up the Wireshark software. You will initially see a window similar to that shown
in above Figure, except that no packet data will be displayed in the packetlisting, packet-
header, or packet-contents window, since Wireshark has not yet begun capturing packets.
3. To begin packet capture, select the Capture pull down menu and select Options. This
will cause the “Wireshark: Capture Options” window to be displayed, as shown in Figure
below.
4
.
Y
o
u
c
a
n
u
s
e
m
o
s
t
o
f
t
Wireshark Capture Options Window
The default values in this window, but uncheck “Hide capture info dialog” under Display
Options. The network interfaces (i.e., the physical connections) that your computer has to
the network will be shown in the Interface pull down menu at the top of the Capture
Options window. In case your computer has more than one active network interface (e.g.,
if you have both a wireless and a wired Ethernet connection), you will need to select an
interface that is being used to send and receive packets (mostly likely the wired
interface). After selecting the network interface (or using the default interface chosen by
Wireshark), click Start. Packet capture will now begin - all packets being sent/received
from/by your computer are now being captured by Wireshark!
5. Once you begin packet capture, a packet capture summary window will appear, as
shown in Figure 4. This window summarizes the number of packets of various types that
are being captured, and (importantly!) contains the Stop button that will allow you to stop
packet capture. Don’t stop packet capture yet.
9. Select the first http message shown in the packet-listing window. This should be the
HTTP GET message that was sent from your computer to the gaia.cs.umass.edu HTTP
server. When you select the HTTP GET message, the Ethernet frame, IP datagram, TCP
segment, and HTTP message header information will be displayed in the packet-header
window3 . By clicking on right pointing and down-pointing arrow sheads to the left side
of the packet details window, minimize the amount of Frame, Ethernet, Internet Protocol,
and Transmission Control Protocol information displayed. Maximize the amount
information displayed about the HTTP protocol. Your Wireshark display should now
look roughly as shown in Figure below. (Note, in particular, the minimized amount of
protocol information for all protocols except HTTP, and the maximized amount of
protocol information for HTTP in the packet-header window).
Requirements
Windows pc – 3Nos
CISCO Packet Tracer Software ( Student Version)
8 port switch – 1 No
Cat-5 LAN cable
Procedure
Theory
A local area network (LAN) is a collection of devices connected together in one physical
location, such as a building, office, or home. A LAN can be small or large, ranging from a home
network with one user to an enterprise network with thousands of users and devices in an office
or school. A LAN comprises cables, access points, switches, routers, and other components that
enable devices to connect to internal servers, web servers, and other LANs via wide area
networks. The advantages of a LAN are the same as those for any group of devices networked
together. The devices can use a single Internet connection, share files with one another, print to
shared printers, and be accessed and even controlled by one another.
Algorithm:
1. In the first step, we append N 0's to the data unit. The value of N is always less than the
number of bits in the data unit(referred to as division which is N+1).
2. In the next step, we use the process of binary division for dividing the newly extended
data by a divisor, and the reminder which we get from this division is referred to as CRC
remainder.
3. In the next step, we replace all the 0's which we append before in the data unit with the
remainder bits. After that, we sent the newly generated data unit to the receiver.
4. The receiver receives the data unit with the CRC remainder. After that, the receiver
divides the data unit by the divisor.
5. If the remainder is zero after dividing the data unit with the divisor, unit data is not
corrupted and can be accepted.
6. If the remainder is not equal to zero after dividing the data unit with the divisor, unit data
is corrupted and will be discarded.
Program:
Sample Output:
5. Flow control mechanisms
Aim :
Algorithm
The Program sends the frames from the Client to the Server with checking for missing frames via
sending an acknowledgement.
/*Server Program*/
import java.net.*;
import java.io.*;
import java.util.*;
public class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket server=new ServerSocket(6262);
System.out.println(“Server established.”);
Socket client=server.accept();
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
System.out.println(“Client is now connected.”);
int x=(Integer)ois.readObject();
int k=(Integer)ois.readObject();
int j=0;
int i=(Integer)ois.readObject();
boolean flag=true;
Random r=new Random(6);
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)
{
System.out.println(“Frame “+k+” recieved”+”\n”+”Data:”+j);
j++;
System.out.println();
}
else
System.out.println(“Frames recieved not in correct order”+”\n”+” Expected farme:” + j +”\n”+ ”
Recieved frame no :”+ k);
System.out.println();
if(j%mod==0 && flag)
{
System.out.println(“Error found. Acknowledgement not sent. “);
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();
}
System.out.println(“Client finished sending data. Exiting”);
oos.writeObject(-1);
}
}
/*Client Program*/
import java.util.*;
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print(“Enter the value of m : “);
int m=Integer.parseInt(br.readLine());
int x=(int)((Math.pow(2,m))-1);
System.out.print(“Enter no. of frames to be sent:”);
int count=Integer.parseInt(br.readLine());
int data[]=new int[count];
int h=0;
for(int i=0;i<count;i++)
{
System.out.print(“Enter data for frame no ” +h+ ” => “);
data[i]=Integer.parseInt(br.readLine());
h=(h+1)%x;
}
Socket client=new Socket(“localhost”,6262);
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
System.out.println(“Connected with server.”);
boolean flag=false;
GoBackNListener listener=new GoBackNListener(ois,x);
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
{
System.out.println(“All elements sent successfully. Exiting”);
flag=true;
}
}while(!flag);
oos.writeObject(-1);
}
}
*Client Output
Sending frame:0
Sending frame:1
Sending frame:2
Sending frame:3
Sending frame:4
Sending frame:5
*/
/*Server Output
Server established.
Client is now connected.
|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||8
6||87||88||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||1
10||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||5
9||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
Error found. Acknowledgement not sent.
|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||3
2||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||1
11||112||113||114||115||116||117||118||119||120||121||122||123||124||125||126||0||1||2|