CN Lab Manual Working
CN Lab Manual Working
What is a 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.
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:-
Operating System − Network Operating Systems is typically installed in the
server and facilitate workstations in a network to share files, database,
applications, printers etc.
Protocol Suite − A protocol is a rule or guideline followed by each computer for
data communication. Protocol suite is a set of related protocols that are laid down
for computer networks. The two popular protocol suites are−
OSI Model ( Open System Interconnections)
TCP / IP Model.
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
Router:-
Routers are networking devices operating at layer 3 or a network layer of the
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.
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 sends
the frames to all the ports, a computer
accepts the ones, whose MAC match
matches the destination MAC address
field. The rest of the frames are discarded
after receiving the required information.
Switch:-
A switch is a Networking device in a computer network that connects other
devices together. Multiple data cables are plugged into a switch to enable
communication between
different networked
devices. Switches manage
the flow of data across a
network by transmitting a
received network packet
only to the one or more
devices for which the
packet is intended.
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 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. Thistable 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 typeof 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.
Gateway:-
The link between two computers to connect to internet or another
network is called gateway. The gateway works like a portal among two programs by
means of communications between protocol
and permit them to share data on same
computers or among different computers.
Gateways are also known as protocol
converter that can perform at any OSI
model layer. The task of a gateway is very
complex.
Working of Gateway:-
A gateway is a network point that works as an access to another
network. Generally in intranet a node can be either a gateway node or the nodes that join
the network are gateways. In large organization where the computers control the traffic
between organization networks are gateway nodes. Like that the computers used by ISP to
connect different user with each other at a time to the internet are gateway nodes. In a
project of any business company computer server work as a gateway nodes and it may be
proxy server or firewall some time. A
gateway may connected to a router because
a router exactly known where to through a
given packet of data that appears at the
gateway then a switch finalize the actual in
and out path of the gateway for the specified
packet .A gateway is a compulsory features
of routes even though other devices can
perform as a gateway. The operating system
mostly used this term and internet
connection sharing act as a gateway and
creating a connection among internal
network.
Date :
Aim :
Algorithm:
Programme:
#include<stdio.h>
#include<string.h>
int main()
int count=0;
int i,parity;
char data[20];
printf("enter data\n");
scanf("%s",&data);
int l=strlen(data);
printf("choose parity\n0:Even\n1:Odd");
scanf("%d",&parity);
for(i=0;i<l;i++)
if(data[i]=='1')
count++;
}
else if(parity==1&&count%2==1)
else
printf("error detected\n");
return 0;
2. CRC Method:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main() {
int i,j,keylen,msglen;
gets(input);
gets(key);
keylen=strlen(key);
msglen=strlen(input);
strcpy(key1,key);
for (i=0;i<keylen-1;i++) {
input[msglen+i]='0';
for (i=0;i<keylen;i++)
temp[i]=input[i];
for (i=0;i<msglen;i++) {
quot[i]=temp[0];
if(quot[i]=='0')
for (j=0;j<keylen;j++)
key[j]='0'; else
for (j=0;j<keylen;j++)
key[j]=key1[j];
for (j=keylen-1;j>0;j--) {
if(temp[j]==key[j])
rem[j-1]='0'; else
rem[j-1]='1';
}
rem[keylen-1]=input[i+keylen];
strcpy(temp,rem);
strcpy(rem,temp);
printf("\nQuotient is ");
for (i=0;i<msglen;i++)
printf("%c",quot[i]);
printf("\nRemainder is ");
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
for (i=0;i<msglen;i++)
printf("%c",input[i]);
for (i=0;i<keylen-1;i++)
printf("%c",rem[i]);
getch();
}
Sample Output
Choose Parity
0 : Even 1 : Odd
Error Detected
Choose Parity
0 : Even 1 : Odd
No Error Detected
5. Flow control mechanisms
Date :
Aim :
Algorithm
import java.io.*;
public class GoBackN {
while(loop)
{
if(ack == window)
loop = false;
else
sent = ack;
}
}
output:-
Date:
Aim :
Algorithm
Programme
#include<stdio.h>
struct node
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
int costmat[20][20];
int nodes,i,j,k,count=0;
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].from[j]=j;
do
count=0;
for(i=0;i<nodes;i++)//We choose arbitary vertex k and we calculate the direct distance from the node
i to k
for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++)
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
printf("\n\n");
getch();
/*
Output
027
201
710
For router 1
For router 2
For router 3
*/
Ex No : 8 Client Server Program using UDP (Chat application)
Date:
Aim:
Algorithm:
Program:
Client:
import java.io.*;
import java.net.*;
class UDPClient
BufferedReader inFromUser =
sendData = sentence.getBytes();
clientSocket.send(sendPacket);
clientSocket.receive(receivePacket);
clientSocket.close();
Server:
import java.io.*;
import java.net.*;
class UDPServer
while(true)
serverSocket.receive(receivePacket);
String sentence = new String( receivePacket.getData());
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
serverSocket.send(sendPacket);
OUTPUT:
hai
FROM SERVER:HAI
hello
FROM SERVER:HELLO
RESULT:
Thus the Client Server Program to create chat application using UDP executed successfully.
EX.NO:9 USE UDP SOCKET FOR IMPLEMENTING DNS
Date:
Aim
Algorithm
• If your frames reach the server it will send ACK signal to client otherwise it will send NACK
signal to client.
PROGRAM :
Import java.io.*;
Imporjava.net.*;
str = str.trim();
if (array[i].equals(str)) return i;
return -1;
while (true)
String capsent;
serversocket.close();
import java.io.*;
import java.net.*;
Senddata = sentence.getBytes();
clientsocket.close();
OUTPUT
Server
$ javac udpdnsserver.java $ java udpdnsserver Press Ctrl + C to Quit Request for host yahoo.com
Request for host cricinfo.com Request for host youtube.com
Client
Aim:
package server;
import javax.net.ssl.*;
import java.io.*;
import java.security.*;
try {
keyStore.load(fis, password);
}
// Create key manager factory
kmf.init(keyStore, password);
System.out.println("Client connected.");
String message;
while ((message = in.readLine()) != null) {
} catch (Exception e) {
e.printStackTrace();
Set up Client
package client;
import javax.net.ssl.*;
import java.io.*;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
try {
new X509TrustManager() {
@Override
throws CertificateException {
@Override
throws CertificateException {
@Override
};
out.println("Hello, Server!");
} catch (Exception e) {
e.printStackTrace();
OutOPut