Académique Documents
Professionnel Documents
Culture Documents
Networking: Networking refers to the total process of creating and using computer networks, with
respect to hardware, protocols and software, including wired and wireless technology.
Communication: The process through which two or more nodes exchange data by using a medium.
Types of network:
The different networks based on size are:
Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Experiment-2
Aim of the Experiment: Program to connect 2 PC’s using peer to peer communication.
Program:
Server Side-
import socket
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(('localhost',8080))
active=True
while active:
data,addr=sock.recvfrom(1024)
data=str(data)
if data=='quit':
sock.close()
else:
print(“received:%s”%data)
d=raw_input("->")
sock.sendto(d,addr)
sock.close()
Client Side-
import socket
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
print("enter quit to exit")
c=str(raw_input("->"))
while c!='quit':
sock.sendto(c,('localhost',8080))
data,server=sock.recvfrom(1024)
print("received:%s"%data)
c=str(raw_input('->'))
sock.sendto(c,('localhost',5555))
sock.close()
Output-
Server Side
hey
->hi
how are you
->fine
Client Side
->hey
hi
->how are you
fine
Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Experiment-3
Aim of the Experiment: Program to implement Stop and Wait protocol
Algorithm:
Step 1: Start the program.
Step 2: Generate a random that gives the total number of frames to be transmitted.
Step 3: Transmit the first frame.
Step 4: Receive the acknowledgement for the first frame.
Step 5: Transmit the next frame
Step 6: Find the remaining frames to be sent.
Step 7: If an acknowledgement is not received for a particular frame retransmit that frame
alone again.
Step 8: Repeat the steps 5 to 7 till the number of remaining frames to be send becomes zero.
Step 9: Stop the program.
Program:
Server side:
import socket
import sys
import time
j=1
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(('localhost',8080))
active=True
while active:
data,addr=sock.recvfrom(1024)
time.sleep(10)
data=str(data)
if data=='quit':
sock.close()
elif data=="":
d="no data received"
else :
print(data+" id= %d"%j)
#c=str(input('->'))
j=j+1
d="ack"
sock.sendto(d,addr)
sock.close()
Client side:
import socket
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
i=1
print("enter quit to exit")
c=str(input("->"))
while c!='quit':
sock.sendto(c,('localhost',8080))
data,server=sock.recvfrom(1024)
#print("%s"%data)
if(data=="ack"):
print("Acknowledgement %d received. Now you can send"%i)
i=i+1
elif(data==""):
print(data)
c=str(input('->'))
sock.sendto(c,('localhost',5555))
sock.close()
Output-
Server Side
hey
how are you
Client Side
->hey
Acknowledgement 1 received. Now you can send.
->how are you
Acknowledgement 2 received. Now you can send.
Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Experiment-4
Aim of the Experiment: Program to implement leaky Bucket algorithm.
Algorithm:
1. Initialize a counter to n at the tick of the clock.
2. If n is greater than the size of the packet, send the packet and decrement the counter by the packet
size. Repeat this step until n is smaller than the packet size.
3. Reset the counter and go to step 1.
Program:
storage=0
no_of_queries=4
bucket_size=10
input_pkt_size=4
output_pkt_size=1
for i in range(0,no_of_queries):
size_left=bucket_size-storage
if(input_pkt_size<=(size_left)):
storage+=input_pkt_size
print(“Buffer size=%d out of bucket size%d”%storage,%bucket_size)
else:
k=input_pkt_size-(size_left)
print(“Packet loss=%d”%k)
storage=bucket_size
print(“Buffer size=%d out of bucket size%d”%storage,%bucket_size)
storage-=output_pkt_size
Output
Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Experiment-5
Aim of the Experiment: Program to implement token bucket algorithm.
Algorithm:
Program:
#include<bits/stdc++.h>
using namespace std;
int data[100];
int m,r=0,f=1,s;
string st;
int main()
{
cout<<"Enter no of bits:";
cin>>m;
for(int i=1;i<100;i++)
data[i]=-1;
while(1)
{
data[f]=0;
s=m+r+1;
if(f>=s)
break;
f=f*2;
r++;
}
int n=m+r;
cout<<"Enter data:\n";
cin>>st;
int j=0;
for(int i=1;i<=n;i++)
{
if(data[i]==-1)
{
data[i]=int(st[j]-'0');
j++;
}
}
f=1;
for(int i=1;i<=r;i++)
{
for(int j=f;j<=n;j=j+f)
{
for(int k=0;k<f;k++)
{
data[f]^=data[j];
j++;
}
}
f=f*2;
}
cout<<"data to be sent :\n";
for(int i=1;i<=n;i++)
cout<<data[i];
}
Output
Enter no of bits:9
Enter data:
100100110
hamming code to be sent :
1110001000110
Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Signature:
Experiment-7
Aim of the Experiment: Program to implement Dijkstra’s algorithm.
Algorithm: -
Step 1: Create a set sptSet (shortest path tree set) that keeps track of vertices included in
shortest path tree, i.e., whose minimum distance from source is calculated and
finalized. Initially, this set is empty.
Step 2: Assign a distance value to all vertices in the input graph. Initialize all distance
values as INFINITE. Assign distance value as 0 for the source vertex so that it is picked first.
Step 3: While sptSet doesn’t include all vertices,
a) Pick a vertex u which is not there in sptSet and has minimum distance value.
b) Include u to sptSet.
c) Update distance value of all adjacent vertices of u. To update the distance
values, iterate through all adjacent vertices. For every adjacent vertex v, if sum of distance
value of u (from source) and weight of edge u-v, is less than the distance value of v, then
update the distance value of v.
PROGRAM: -
#include<stdio.h>
#define INFINITY 9999
#define MAX 10
void dijkstra(int G[MAX][MAX],int n,int startnode);
int main()
{ int G[MAX][MAX],i,j,n,u;
printf("Enter no. of vertices:");
scanf("%d",&n);
printf("\nEnter the adjacency matrix:\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&G[i][j]);
printf("\nEnter the starting node:");
scanf("%d",&u);
dijkstra(G,n,u);
return 0;
}
void dijkstra(int G[MAX][MAX],int n,int startnode)
{ int cost[MAX][MAX],distance[MAX],pred[MAX];
int visited[MAX],count,mindistance,nextnode,i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
if(G[i][j]==0)
cost[i][j]=INFINITY;
else
cost[i][j]=G[i][j];
for(i=0;i<n;i++)
{ distance[i]=cost[startnode][i];
pred[i]=startnode;
visited[i]=0;
}
distance[startnode]=0;
visited[startnode]=1;
count=1;
while(count<n-1)
{ mindistance=INFINITY;
for(i=0;i<n;i++)
if(distance[i]<mindistance&&!visited[i])
{ mindistance=distance[i];
nextnode=i;
}
visited[nextnode]=1;
for(i=0;i<n;i++)
if(!visited[i])
if(mindistance+cost[nextnode][i]<distance[i])
{ distance[i]=mindistance+cost[nextnode][i];
pred[i]=nextnode;
}
count++;
}
for(i=0;i<n;i++)
if(i!=startnode)
{ printf("\nDistance of node%d=%d",i,distance[i]);
printf("\nPath=%d",i);
j=i;
do
{ j=pred[j];
printf("<-%d",j);
}while(j!=startnode);
}
}
OUTPUT:-
Enter no. of vertices: 5
Enter the adjacency matrix:
10231
00111
21200
10100
11111
Enter the starting node:2
Distance of node0=2
Path=0<-2
Distance of node1=1
Path=1<-2
Distance of node3=2
Path=3<-1<-2
Distance of node4=2
Path=4<-1<-2
Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Signature:
Experiment-8
Aim of the Experiment: Program to implement bit stuffing and destuffing.
Algorithm:
1. Start
2. Initialize the array for transmitted stream with the special bit pattern 0111 1110
which indicates the beginning of the frame.
3. Get the bit stream to be transmitted in to the array.
4. Check for five consecutive ones and if they occur, stuff a bit 0
5. Display the data transmitted as it appears on the data line after appending 0111 1110
at the end
6. For de−stuffing, copy the transmitted data to another array after detecting the stuffed
bits
7. Display the received bit stream
8. Stop
Program:
#include<iostream>
#include<string.h>
using namespace std;
char str[100],str2[100];
main()
{
int i,j=0,l,k=0,t=0,z=0;
cout<<"Enter the data frame\n";
cin>>str;
//int l=str.length();
l=strlen(str);
for(i=0;i<l;i++)
{
if(str[i]=='0'&&str[i+1]=='1'&&str[i+2]=='1'&&str[i+3]=='1'&&str[i+4]=='1'&&str[i+5]=='1')
{
for(int k=0;k<6;k++)
{
str2[j]=str[i];
i++;
j++;
}
str2[j]='0';j++;i--;
}
else
{
str2[j]=str[i];
j++;
}
}
z=strlen(str2);
cout<<”Data to be sent is:\n"
for(i=0;i<z;i++)
cout<<str2[i];
}
Output:
Enter the data frame
1011111011111
Data to be sent is:
101111100111110
Bit Destuffing:
Program:
#include<bits/stdc++.h>
using namespace std;
main()
{
string res(50,' '),s;
int z=0,o=0,l=0,k=0;
cout<<"enter the data received:";
cin>>s;
l=s.length();
for(int i=0;i<l;i++)
{
if(s[i]=='0')
{
o=0;
z=1;
}
else
o++;
res[k]=s[i];
k++;
if(z==1 && o==5)
{
i++;
z=0;
o=0;
}
}
cout<<res;
}
Output:
enter the data received:01111101111110
0111111111110
Conclusion: Bit stuffing and destuffing is implemented successfully.
Submitted By:
Priyabrata Mohapatra
Roll No : 1602040017
Computer Science and Engineering
Signature:
Experiment-9
Aim of the Experiment: Program to implement character stuffing and destuffing.
Program:
#include<bits/stdc++.h>
using namespace std;
main()
{
string res(100,' '),s;
int l=0,k=0;
cout<<"enter the data to be sent:";
cin>>s;
l=s.length();
for(int i=1;i<7;i++)
res[i]='1';
res[0]='0';
res[7]='0';
k=8;
for(int i=0;i<l;i++)
{
if(s[i]=='0' && s[i+1]=='1' && s[i+2]=='1' && s[i+3]=='1' && s[i+4]=='1' && s[i+5]=='1' &&
s[i+6]=='1' && s[i+7]=='0')
{
res[k]='0';
k++;
for(int j=0;j<6;j++)
{
res[k]='1';
k++;
}
res[k]='0';k++;
}
for(int j=0;j<8;j++)
{
res[k]=s[i];
k++;
i++;
}
}
res[k]='0';k++;
for(int i=1;i<7;i++)
{
res[k]='1';k++;
}
res[k]='0';
cout<<res;
}
Output:
enter the data to be sent:011101111101111110
01111110011101111011111101111110
Byte destuffing
Program:
#include<bits/stdc++.h>
using namespace std;
main()
{
string res(100,' '),s;
int l=0,k=0;
cout<<"enter the data to be sent:";
cin>>s;
l=s.length();
for(int i=0;i<l;i++)
{
if(s[i]=='0' && s[i+1]=='1' && s[i+2]=='1' && s[i+3]=='1' && s[i+4]=='1' && s[i+5]=='1' &&
s[i+6]=='1' && s[i+7]=='0')
{
i=i+8;
}
for(int j=0;j<8;j++)
{
res[k]=s[i];
k++;
i++;
}
}
cout<<res;
}
Output:
enter the data to be sent:0111111011111101
11111101
Conclusion: Character stuffing and destuffing is implemented successfully.
Submitted By:
Priyabrata Mohapatra
Roll No: 1602040017
Computer Science and Engineering
Signature: