0% found this document useful (0 votes)
19 views65 pages

CN Lab Manual Total (EC692)

The document is a laboratory manual for the Computer Networking course (EC692) at Meghnad Saha Institute of Technology, detailing the vision, mission, program outcomes, and specific course objectives. It includes guidelines for laboratory conduct, a list of experiments, and mappings of course outcomes to program outcomes. The manual aims to equip students with essential networking skills and knowledge through practical experiments and theoretical understanding.

Uploaded by

loki odinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views65 pages

CN Lab Manual Total (EC692)

The document is a laboratory manual for the Computer Networking course (EC692) at Meghnad Saha Institute of Technology, detailing the vision, mission, program outcomes, and specific course objectives. It includes guidelines for laboratory conduct, a list of experiments, and mappings of course outcomes to program outcomes. The manual aims to equip students with essential networking skills and knowledge through practical experiments and theoretical understanding.

Uploaded by

loki odinson
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 65

MSIT/ECE/ Computer Networking Laboratory /EC692

COMPUTER NETWORKING

LABORATORY MANUAL

B.TECH
(3rd Year–2nd Sem)

Sub Code: EC692

Version: 1.1

Department of Electronics and Communication Engineering


MEGHNAD SAHA INSTITUTE OF TECHNOLOGY

Nazirabad, P.O.-Uchhepota, Kolkata 700 150


www.msit.edu.in
1
MSIT/ECE/ Computer Networking Laboratory /EC692

COMPUTER NETWORKING

LABORATORY MANUAL

Prepared by,

…………………………………………
Prof.Joyanto Roychoudhary
Assistant Professor, Dept. of ECE.
Meghnad Saha Institute of Technology

Approved by,

……………………….
H.O.D, Dept. of ECE,
Meghnad Saha Institute of Technology

2
MSIT/ECE/ Computer Networking Laboratory /EC692

INDEX
Topic Pages
Vision and Mission of the Department 4
Program Outcomes (POs) 5
PEOs/PSOs 6
Course Outcomes (COs) 7
CO-PO and CO-PSO Mapping 8
Do’s and Don’ts 9
Guidelines of the Laboratory 10
MAKAUT Syllabus 11
List of Experiments 12
Manual of Experiment no.1 14
Manual of Experiment no.2 17
Manual of Experiment no.3 21
Manual of Experiment no.4 25
Manual of Experiment no.5 29
Manual of Experiment no.6 32
Manual of Experiment no.7 35
Manual of Experiment no.8 37
Manual of Experiment no.9 46
Manual of Experiment no.10 53
Manual of Experiment no.11 58
Manual of Experiment no.12 60

3
MSIT/ECE/ Computer Networking Laboratory /EC692

1. Vision of the Department:

To strive for excellence in education & research in Electronics &


Communication Engineering to offer engineering solutions to meet new
challenges.

2. Mission of the Department:

M1:To create efficient and competent professionals by imparting quality


educations in the field of Electronics and Communication Engineering which can
contribute to the advancement of science and technology.

M2: To promote research and development activities in the field of Electronics and
Communication Engineering, leading to the creation of knowledge and of
intellectual property.

M3: To provide value-based education leading to entrepreneurial initiatives toward


socio economic development of society.

M4:To create effective and ethical professionals, capable of accepting new


challenges in the emerging field of science and engineering through lifelong
learning.

4
MSIT/ECE/ Computer Networking Laboratory /EC692

3. Program Outcomes (POs)

Engineering Graduates will be able to:


1. Engineering Knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. Problem Analysis: Identify, formulate, review research literature, and analyze complex
engineering problems reaching substantiated conclusions using first principles of mathematics,
natural sciences, and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
consideration for public health and safety, and the cultural, societal, and environmental
consitions.
4. Conduct investigations of complex problems: Use research-based knowledge and research
methods including design of experiments, analysis and interpretation of data, and synthesis of the
information to provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to
the professional engineering practice.
7. Environment and sustainability: Understand the impact of professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms
of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in
diverse teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and write
effective reports and design documentation, make effective presentations, and give and receive
clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the
engineering and management principles and apply these to one's own work, as a member and
leader in a team, to manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.

5
MSIT/ECE/ Computer Networking Laboratory /EC692

4. Program Educational Objectives (PEOs)


1. The graduates shall have a good understanding of the Electronics and Communication
Engineering fundamentals for identifying and analyzing real-life engineering problems in
communication, automation, and VLSI industries.
2. The graduates will be encouraged in research and innovative approaches for successful career
growth in VLSI, communication, embedded and automation industries and blossom into
entrepreneurs, scientists, and technocrats.
3. The graduates shall have the expertise in cutting-edge interdisciplinary technology like Data
Science, Artificial Intelligence, Image Processing, Machine Learning, and IoT using modern
software tools for measurable and impactful contributions that strongly support the
organization’s high-level goals.
4. The graduates shall be inculcated with professional ethics, and managerial and communication
skills to develop ingenious solutions for the benefit of society and the environment
.
5. Program Specific Outcomes (PSOs):

1. Analyze specific engineering problems relevant to electronics and communication engineering


by applying the knowledge of basic sciences, engineering mathematics, and fundamentals.
2. Design electronics and communication systems containing electronic devices, embedded
systems, software, and hardware using significant analytical knowledge in electronics and
communication engineering and allied domains, applying modern tools.
3. Apply the specific knowledge of electronics and communication engineering for environmental,
health, safety, and cultural issues.

6
MSIT/ECE/ Computer Networking Laboratory /EC692

6. Course Outcomes (COs):


EC692 Computer Networking Laboratory

Objective:
To Learn and Understand basic Computer networking Concepts.

The students will be able to

EC692.1 Discuss the basics of IPC and NIC installation and


configuration. BT-2

EC692.2
Recognize the different networking cables, connectors, Hubs
BT-2
and Switches.
EC692.3
Demonstrate the TCP/UDP Socket programming. BT-3

EC692.4
Explain a Prototype multithreaded Server program. BT-2

EC692.5
BT-3
Show the Data Link Layer Flow control mechanism.
EC692.6 Identify the Data Link Layer error detection and control
mechanisms. BT-2

7
MSIT/ECE/ Computer Networking Laboratory /EC692

7.1 Correlations between COs & POs

Course PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Outcomes

EC692.1 -
3 3 3 3 - 2 2 - 2 2 3
EC692.2 -
3 3 3 3 - 2 2 - 2 2 3
EC692.3 -
3 3 3 3 - 2 2 - 2 2 3
EC692.4 -
3 3 3 3 - 2 2 - 2 2 3
EC692.5 -
3 3 3 3 - 2 2 - 2 2 3
EC692.6
-
3 3 3 3 - 2 2 - 2 2 3
EC692 3 3 3 3 - 2 2 - 2 2 - 3

7.2Correlations between COs & PSOs

Course PSO1 PSO2 PSO3


Outcomes

EC692.1 3 2 2
EC692.2 3 2 2
EC692.3 3 2 2
EC692.4
3 2 2
EC692.5 3 2 2
EC692.6
3 2 2
EC692 3
2 2

8
MSIT/ECE/Computer Networking Laboratory/EC692

8. Do’s and Don’ts in CN Laboratory

Do’s Don’ts
Maintain Discipline and follow the Guidelines of Do not exceed the voltage Rating of the
the Laboratory. equipments/components.

Arrange the chairs/tools and equipments Avoid loose connections and short circuits.
properly before leaving the lab.

Bring your lab copies everyday. Avoid stepping on electrical wires or any
other computer cables.
Switch off the instruments/computers after Do not touch, connect or disconnect any plug
completing the experiments. or cable without permission.
Collect the components as per the experiments Do not insert a pen Drive or similar kind
& return after completion. devices without permission.

Before leaving the lab students should save Do not come late to the lab.
their programs and collect their belongings.

Follow the directions of the faculty/Technical Do not use chat rooms, online games, or
Assistant. multiuser domains.

9
MSIT/ECE/Computer Networking Laboratory/EC692

9. Guidelines of the Laboratory


1. Students should not enter the lab without the permission of the lab in-Charge/TA.

2. Every student/faculty should mention their name, time, and computer serial number in the log
book before accessing the computers.

3. Students to use the laboratories in their allotted classes only. They can use laboratories for
project work/ Lab practice with prior permission from Lab-In-Charge.

4. Do not access the lab in absence of the faculty member/TA.

5. Cleanliness and discipline should be maintained properly.

6. Bags to be kept outside the Lab.

7. Pen drive is not allowed. Shut down the computers and switch off after completion of
Experiments.

8. Components and multimeters will be issued to groups before starting of experiments.


Ensure returning all components to TA before leaving the laboratory.

9. Get the circuit/set up checked by TA/Faculty before it is connected to power.

10. Switch off all equipment of laboratories after completion of experiment.

10
MSIT/ECE/Computer Networking Laboratory/EC692

10. MAKAUT Computer Networking Laboratory (EC692) Syllabus

•IPC (Message queue)

• NIC Installation & Configuration (Windows/Linux)

• Familiarization with

Networking cables (CAT5, UTP)

Connectors (RJ45, T-connector)

Hubs, Switches

• TCP/UDP Socket Programming

• Multicast & Broadcast Sockets

• Implementation of a Prototype Multithreaded Server

• Implementation of

Data Link Layer Flow Control Mechanism (Stop & Wait, Sliding Window)

Data Link Layer Error Detection Mechanism (Cyclic Redundancy Check)

Data Link Layer Error Control Mechanism (Selective Repeat, Go Back N)

11
MSIT/ECE/Computer Networking Laboratory/EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Computer networking laboratory (EC692)

LIST OF EXPERIMET

List of Experiments:
ASSIGNMENT /
ASSIGNMENT / EXPERIMENTS TAXONOMICAL MAPPING WITH
EXPERIMENTS
ACTIVITY COS/POS
NO.
Installation & Configuration CO1
1 BT2 PO1-PO5,PO8-
of NIC. PO10,PO12
Familiarization with Networking
cable (CAT5, UTP), Connectors
(RJ45,T-connector) ,Hubs and CO2
2 BT2 PO1-PO5,PO9-
switches etc.
PO10,PO12

3 Introduction to Python.

Interprocess Communication CO1


4 BT2 PO1-PO5,PO9-
using Message Queue. PO10,PO12
Introduction to Socket CO3
5 BT3 PO1-PO5,PO9-
Programming.
PO10,PO12
Implementation of TCP Socket
Programming. CO3
6 BT3 PO1-PO5,PO9-
PO10,PO12

Implementation of UDP Socket


Programming. CO3
7 BT3 PO1-PO5,PO9-
PO10,PO12

Implementation of a Prototype
Multithreaded Server. CO4
8 BT2 PO1-PO5,PO9-
PO10,PO12

12
MSIT/ECE/Computer Networking Laboratory/EC692
Implementation of Data Link
CO6
9 Layer Error Detection Mechanism BT2 PO1-PO5,PO9-
(Cyclic Redundancy Check) PO10,PO12

Implementation of Data Link


Layer Flow Control Mechanism. CO5
10 BT3 PO1-PO5,PO9-
PO10,PO12

To find system date and time


using Socket Programming. CO3
11 BT3 PO1-PO5,PO9-
PO10,PO12

Building a Network Topologies with


Cisco Packet Tracer.
12

13
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:1
Name of the Experiment: Installation & Configuration of NIC.

Objective: To study NIC Installation & Configuration. [EC692.1]

2. Theory: NIC is also commonly referred to as a network adapter and is an expansion card that enables a
computer to connect to a network such as a home network and/or the Internet using a Ethernet cable with a RJ -
45 connector.
If we want to add our computer to a network or a network device like a router then we need to install or
configure our network card. Every new computer and motherboard nowadays has a built-in network port known
as RJ45 socket. If we have an older computer or a motherboard that does not have a built in RJ45 socket then
our only option is to add a PCI or USB network card if we wish to connect to a network.

Fig.1 View of typical NIC

Procedure:

Installation process in windows:


1. First step is to read the user's guide and familiarize yourself with the new card.
2. Power down PC and remove the AC power cord.
3. Open the computer case.

4. Find an available Peripheral Component Interconnect (PCI) slot on the motherboard and remove slot
insert if one exists.
14
MSIT/ECE/Computer Networking Laboratory/ EC692

5. Carefully remove the network card from its static-proof plastic envelope, and slide it into the slot.
6. Seat the card in the slot firmly with gentle pressure along the length of the card, especially right about
the slot itself.
7. screw the card to the computer frame, but do not over tighten.
8. Close the computer case.
9. Plug your computer in and power it up.
10. Click Start, then click Control Panel.
11. In Category View (vs. Classic View) click Performance and Maintenance.
12. Click "System" icon at bottom of window.
13. Click the Hardware tab.
14. Click the Device Manager button.
15. Double-click Network Adapters.
16. Beneath it should appear the name of your Ethernet card.
17. Next, double click the name of your Ethernet adapter.
18. If the text in the "Device Status" box says "This device is working properly.", then we successfully
installed thecard.
19. After the drivers have been installed successfully, we can see a network card listed under windows
device manager. To go to the device manager click Start -> Control Panel -> System and Security ->
Device Manager.
Configuration:
Go to network sharing center by clicking Start -> Control panel -> Network and Internet -> Network and
Sharing Center.
Click Properties -> (on Network area connections status) -> Internet protocol version 4 (TCP/IPv4) ->
Properties.
If we have many computers on a network i.e. our Desktop PC, our Laptop then its a good idea to fix t he IP
Address for each device. This is called static IP address. By fixing the IP address we can easily identify each
computer on the network.

3. Requirement:
Apparatus:

 P.C
 Internet
 RJ45 Connector
 NIC

Components:

4. Results and Simulations:


Important Commands in networking:
 ipconfig
 ipconfig/all
 getmac
 arp –a
 ping (ipaddress) -t

15
MSIT/ECE/Computer Networking Laboratory/ EC692

5. Discussions & Conclusions:

6. Area of applications: Knowledge can be applied to understand basic networking.

7. Question Banks:

 What do you mean by computer networking?


 What is IP address?
 What is MAC address?

8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

16
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:2
Name of the Experiment: Familiarization with Networking cable (CAT5, UTP), Connectors
(RJ45,Tconnector) ,Hubs and switches etc.

Objective: To familiarize with Networking cable (CAT5, UTP), Connectors (RJ45, T-connector) ,Hubs
and switches etc.[EC692.2]

2. Theory:
Networking Cable: Networking cables are networking hardware used to connect one network device to other
network devices or to connect two or more computers to share printers, scanners etc.
.
CAT5 Cable -Category 5 cable, commonly referred to as Cat 5, is a twisted pair cable for computer networks.
The cable standard provides performance of up to 100 MHz and is suitable for most varieties of Ethernet over
twisted pair.

Fig2.1 CAT5 Cable

UTP- UTP stands for Unshielded Twisted Pair. Inside a UTP cable is up to four twisted pairs of copper wires,
enclosed in a protective plastic cover, with the greater number of pairs corresponding to more bandwidth. The
two individual wires in a single pair are twisted around each other, and then the pairs are twisted around each
other, as well.

17
MSIT/ECE/Computer Networking Laboratory/ EC692

Fig2.2 UTP

Connectors: A connector is a device that terminates a segment of cabling or provides a point of entry for
networking devices such as computers, hubs, and routers.

Fig2.3 RJ45 Connector

Fig 2.4 T Connector

18
MSIT/ECE/Computer Networking Laboratory/ EC692

Hub: A hub is a physical layer networking device which is used to connect multiple devices in a network. They
are generally used to connect computers in a LAN. A hub has many ports in it. A computer which intends to be
connected to the network is plugged in to one of these ports.

Fig 2.6 Hub

Switch:
A switch is a 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. Each networked device connected to a switch can be identified by its network address,
allowing the switch to direct the flow of traffic maximizing the security and efficiency of the network.

A switch is more intelligent than an Ethernet hub, which simply retransmits packets out of every port of the hub
except the port on which the packet was received, unable to distinguish different recipients, and achieving
overall lower network efficiency.

An Ethernet switch operates at the data link layer (layer 2) of the OSI model to create a separate collision
domain for each switch port. Each device connected to a switch port can transfer data to any of the other ports at
any time and the transmissions will not interfere.[a] Because broadcasts are still being forwarded to all connected
devices by the switch, the newly formed network segment continues to be a broadcast domain. Switches may
also operate at higher layers of the OSI model, including the network layer and above. A device that also
operates at these higher layers is known as a multilayer switch.

Fig 2.7 Switch

19
MSIT/ECE/Computer Networking Laboratory/ EC692

5. Discussions & Conclusions:

6. Area of applications: Knowledge can be applied to understand basic networking.

7. Question Banks:

What are the 3 basic functions of a switch?


What is the advantage of Switch over Hub?
What is MAC address?

8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

20
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:3
Name of the Experiment: Introduction to Python Programming.

Objective: To understand the basic python programming.

2. Theory: Python has a simple syntax similar to the English language. Python has syntax that allows
developers to write programs with fewer lines than some other programming languages. Python runs on an
interpreter system, meaning that code can be executed as soon as it is written.

3. Requirement:

P.C
Python Software

4.Results and Simulation:

Program:

#Write a program to perform addition, subtraction, multiplication, division, and modulo division of two
integer

a=5
b=4
sum=a+b
print(sum)
sub=a-b
print(sub)
Mult=a*b
print(Mult)
div=a/b
print(div)
Modulo=a%b
print(Modulo)

#Write a program to reassign values to a variable

val='hello'
print(val)
21
MSIT/ECE/Computer Networking Laboratory/ EC692

val=100
print(val)
val=12.34
print(val)

#Commands to show the applications of string


str1='Good Morning'
str2='It is a nice day'
str1+=str2
print(str1)

str='Hello'
print(str+'4')
print(str*5)

#program to demonstrate a tuple

my_tuple=(1,2,3,4,5,6,7,8)
print(my_tuple[1:4])

#Program to demonstrate operation on a tuple

Tup=('a','b',43,1.23)
Tup1=('d',78)
print(Tup)
print(Tup[0])
print(Tup[1:3])
print(Tup[2:])
print(Tup[:2])
print(Tup*2)
print(Tup+Tup1)

#write a program to enter a number and display it's hex and octal equivalent and it's sqrt

import math
a=25
print(math.sqrt(a))
print(hex(a))
print(oct(a))

#Write a program to determine whether a person is eligible to vote or not

n=int(input("Enter a age of yours:"))


if (n>=18):
print("You are eligible for vote")
else:
yrs=18-n
22
MSIT/ECE/Computer Networking Laboratory/ EC692

print("you have to wait another"+ str(yrs)+ "to cast your vote")

#Program to find large of two integer

a=int(input('enter the value of a:'))


b=int(input('enter the value of b:'))
if(a>b):
large=a
else:
large=b
print('large=',large)

#Program to find even or odd for a given integer


num=int(input('enter the number:'))
if(num%2==0):
print(num,'is even')
else:
print(num,'is odd')

#Write a python program using for loop to calculate the factorial of a number
import math
n=int(input("enter the number:"))
fact=1
if n<0:
print("Factorial doesn't exist")
elif (n==0):
print("Factorial is 0 or 1")
else:
for i in range(1,n+1):
fact=fact*i
print(fact)

#program to add two integers using function

def add(a,b):
sum1=a+b
return sum1

print("sum1",add(5,6))

#Program to add two integer using function

def total(a,b):
result=a+b
23
MSIT/ECE/Computer Networking Laboratory/ EC692

print('sum of',a,'and',b, '=',result)


a=int(input('enter the 1st number:'))
b=int(input('enter the 2nd number:'))
total(a,b)

#Program to find even or odd for a given integer using functions and return statements
def evenodd(a):
if(a%2==0):
return 1
else:
return -1
a=int(input('enter the number:'))
flag=evenodd(a)
if(flag==1):
print('number is even')
if(flag== -1):
print('number is odd')

5. Discussions & Conclusions:

6. Area of applications: Knowledge can be applied to understand basics of socket programming on python
base.

References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

24
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:4
Name of the Experiment: Inter-process communication using Message Queue.

Objective: To perform inter-process communication through message queue. [EC692.1]

2. Theory:
IPC message queues are transient memory areas, typically provided by the underlying operating system, used
for communication between clients and servers. All processes can exchange information through access to a
common system message queue. The sending process places a message (via some (OS) message -passing
module) onto a queue which can be read by another process.
Inter-process communication (IPC) refers specifically to the mechanisms an operating system provides to allow
the processes to manage shared data. Inter process communication (IPC) is used for exchanging data between
multiple threads in one or more processes or programs. The Processes may be running on single or multiple
computers connected by a network.

Fig. 4.1 Inter-Process Communication between two processes, produce and consume

The service that sends the message is known as the produce, while the service that receives and responds to
messages is known as the consume. This is how the services communicate with one another.

25
MSIT/ECE/Computer Networking Laboratory/ EC692

Fig.4.2 Block Diagram of Message Queue

Fig. 4.3 Message Queue between two processes communicating with each other.

Procedure:
 Step 1 − Create a message queue or connect to an already existing message queue.
 Step 2 − Write into message queue.
 Step 3 − Read from the message queue.
 Step 4 − Perform control operations on the message queue.

3. Requirement:

 P.C
 Python software Platform
26
MSIT/ECE/Computer Networking Laboratory/ EC692

4. Results and Simulations:


Program

# Thread communication using a queue

import multiprocessing
import time
import random

def produce(q):

# Create 1 to 10 items and add it to the Queue

for i in range(1,11):
print("Producing item: " , i)
q.put(i)
consume(q)
time.sleep(random.random())

def consume(q):

while True:
if not q.empty():
value = q.get(True)
print("Receiving item: %s" % (value))

time.sleep(random.random())
return
else:
break
if __name__ == '__main__':
q = multiprocessing.Queue()

t1 = multiprocessing.Process(target=produce, args=(q,))
27
MSIT/ECE/Computer Networking Laboratory/ EC692

t2 = multiprocessing.Process(target=consume, args=(q,))

t1.start()
t1.join()

t2.start()
t2.join()

print('')
print('All items produced and consumed')

5. Discussions & Conclusions:

6. Area of applications:
Message queues allow different parts of a system to communicate and process operations asynchronously. A
message queue provides a lightweight buffer which temporarily stores messages, and endpoints that allow
software components to connect to the queue in order to send and receive messages.

7. Question Banks:
 What is the full form of IPC?
 What are the models in IPC?
 What is SSSQ?

8. References:
Data Communications and Networking By Behrouz AForouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

28
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:5
Name of the Experiment: Introduction to Socket Programming.

Objective: To familiarize with Socket Programming. [EC692.3]

2. Theory:
It is possible to establish a logical connecting point between a server and a client so that communication can be
done through that point, this point is called socket. Each socket is given an identification number which is called
port number. Establishing communication between a server and a client using sockets is called socket
programming. The server forms the listener socket while the client reaches out to the server. They are the real
backbones behind web browsing. In simpler terms, there is a server and a client.

We should use a new port number for each new socket. The port number from 0 to 1023 are used by our
computer system for various application or services and we should avoid using these port numbers in our
networking programs.

3. Requirement:
Apparatus:

 P.C
 Internet
 Python Software

4. Results and Simulations:

Program 1:
A python program to find the IP address of a website.

import socket
host = 'www.yahoo.co.in'
try:
addr = socket.gethostbyname(host)
print('IP Address= ' + addr)
except socket.gaierror:
print ('The website does not exist')

Program2:

A python program to download animage from internet and save it into our computer.
29
MSIT/ECE/Computer Networking Laboratory/ EC692

Downloading an image from internet.


import urllib.request

url="https://api.time.com/wp-content/uploads/2018/03/gettyimages-932825264.jpg"

download=urllib.request.urlretrieve(url, "image.jpg")

Program3:

A python program to retrieve different parts of URL and display them.

import urllib.parse
url = 'http://www.dreamtechpress.com:80/engineering/computer-science.html'
tpl = urllib.parse.urlparse(url)
print(tpl)
print('scheme= ', tpl.scheme)
print('Net location= ' ,tpl.netloc)
print('path= ' ,tpl.path)
print('parameters= ', tpl.params)
print('port number= ' ,tpl.port)
print('total url= ' , tpl.geturl())

Program4:

A Python program to download a webpage from internet and save it into our computer.

import urllib.request
try:
file = urllib.request.urlopen("https://www.python.org/")
content = file.read()
except urllib.error.HTTPError:
print('The web page does not exist')
exit()
f = open('myfile.html', 'wb')
f.write(content)
f.close()

5. Discussions & Conclusions:

30
MSIT/ECE/Computer Networking Laboratory/ EC692

6. Area of applications: Knowledge can be applied to understand basic socket programming application in
networking.

7. Question Bank:
 What is a socket in python?
 How do we send data to a socket in python?
 What does a socket consist of?

8. References:
Data Communications and Networking By Behrouz AForouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

31
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:6
Name of the Experiment: Implementation of TCP Socket Programming.

Objective: To create Server and Client using TCP Socket Programming.[EC692.3]

2. Theory:
A server is a program that provide services to other computers on the network or internet. Similarly, a client is a
program that receive services from the servers. When a sever wants to communicate with client, there is a need
of a socket.
It is possible to establish a logical connecting point between a server and a client so that communication can be
done through that point, this point is called socket. Each socket has given an identification number which is
called port number.Establishing communication between a server and a client using sockets is called socket
programming.We should use a new port number for each new socket. The port number from 0 to 1023 are used
by our computer system for various application or services and we should avoid using these port numbers in our
networking programs.Socket programming is started by importing the socket library and making a simple
socket.

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Here we made a socket instance and passed it two parameters. The first parameter is AF_INET and the
second one is SOCK_STREAM. AF_INET refers to the address-family ipv4. The SOCK_STREAM means
connection-oriented TCP protocol.
Now we can connect to a server using this socket.
The Transmission Control Protocol (TCP) is one of the main protocols of the Internet protocol suite. It
originated in the initial network implementation in which it complemented the Internet Protocol (IP). Therefore,
the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered, and error-checked delivery
of a stream of octets (bytes) between applications running on hosts communicating via an IP network. Major
internet applications such as the World Wide Web, email, remote administration, and file transfer rely on TCP,
which is part of the Transport Layer of the TCP/IP suite.
TCP is connection-oriented, and a connection between client and server is established before data can be sent.
The server must be listening (passive open) for connection requests from clients before a connection is
established.

32
MSIT/ECE/Computer Networking Laboratory/ EC692

3. Requirement:
Apparatus:

 P.C
 Internet
 Python Software

4. Results and Simulations:

Program Code:
PART-A
Create Server (Using TCP/IP Protocol)
import socket
host = 'localhost'
port = 12345
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((host,port))
print("socket binded to port",port)
s.listen(1)
print("socket is listening")
c,addr = s.accept()
print("connection from:" , str(addr))
c.send(b"Hello client, how are U")
msg = "Bye!"
c.send(msg.encode())
c.close()

PART-B
Create Client
import socket
host = 'localhost'
port = 12345
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,port))
msg = s.recv(1024)
while msg:
print('Received:' + msg.decode())
msg = s.recv(1024)

s.close()

5. Discussions & Conclusions:

33
MSIT/ECE/Computer Networking Laboratory/ EC692

6. Area of applications: Knowledge can be applied to understand basic socket programming application in
networking.

7. Question Bank:
What is socket timeout?

Why are sockets used?

What is the difference between socket and port?

8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

34
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:7
Name of the Experiment: Implementation of UDP Socket Programming.

Objective: To create Server and Client using UDP Socket Programming. [EC692.3]

2. Theory:
A server is a program that provide services to other computers on the network or internet. Similarly, a client is a
program that receive services from the servers. When a sever wants to communicate with client, there is a need
of a socket.
It is possible to establish a logical connecting point between a server and a client so that communication can be
done through that point, this point is called socket. Each socket has given an identification number which is
called port number.
Establishing communication between a server and a client using sockets is called socket programming.
We should use a new port number for each new socket. The port number from 0 to 1023 are used by our
computer system for various application or services and we should avoid using these port numbers in our
networking programs.
The User Datagram Protocol, or UDP, is a communication protocol used across the Internet for especially time-
sensitive transmissions such as video playback or DNS lookups. It speeds up communications by not formally
establishing a connection before data is transferred.

3. Requirement:
Apparatus:

 P.C
 Internet
 Python Software

4. Results and Simulations:

Program:
PART-A
Create Server (Using UDP Protocol)
import socket
import time
host = 'localhost'
port = 12345
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
time.sleep(5)
35
MSIT/ECE/Computer Networking Laboratory/ EC692

s.sendto(b"helloclient,how are U" ,(host,port))

msg = "Bye!"
s.sendto(msg.encode(), (host,port))
s.close()

PART-B
Create Client
import socket
host = 'localhost'
port = 12345
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind((host,port))
msg,addr = s.recvfrom(1024)
try:
s.settimeout(5)
while msg:
print('Received:' + msg.decode())
msg,addr = s.recvfrom(1024)
except socket.timeout:
print('Time is over and hence terminating....')

s.close()

5. Discussions & Conclusions:

6. Area of applications: Knowledge can be applied to understand basic socket programming application in
networking.

7. Question Bank:
 What are the features of UDP?
 Why UDP is not secure?
 Why is UDP faster than TCP?

8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

36
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name:Computer Networking laboratory
Course Code: EC692

Experiment No:8
Name of the Experiment: Implementation of a Prototype Multithreaded Server.

Objective: To implement of a Prototype Multithreaded Server. [EC692.4]

2. Theory:

A thread is a sequence of such instructions within a program that can be executed independently of other code.
A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is
called a thread, and each thread defines a separate path of execution.Multithreading is a process of executing
multiple threads simultaneously in a single process. Multithreaded Socket Programming describes that
a Multithreaded Socket Server can communicate with more than one client at the same time in the same
network.A _thread module & threading module is used for multi-threading in python, these modules help in
synchronization and provide a lock to a thread in use.

3. Requirement:
Apparatus:

 P.C
 Internet
 Python Software

4. Results and Simulations:

Program 1:

Server Code
import socket

import sys

import traceback

from threading import Thread

37
MSIT/ECE/Computer Networking Laboratory/ EC692

def main():

start_server()

def start_server():

host = "127.0.0.1"

port = 8888 # arbitrary non-privileged port

soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

soc.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # SO_REUSEADDR flag tells the kernel to reuse a local


socket in TIME_WAIT state, without waiting for its natural timeout to expire

print("Socket created")

try:

soc.bind((host, port))

except:

print("Bind failed. Error : " + str(sys.exc_info()))

sys.exit()

soc.listen(5) # queue up to 5 requests

print("Socket now listening")

# infinite loop- do not reset for every requests

while True:

connection, address = soc.accept()

ip, port = str(address[0]), str(address[1])

print("Connected with " + ip + ":" + port)


38
MSIT/ECE/Computer Networking Laboratory/ EC692

try:

Thread(target=client_thread, args=(connection, ip, port)).start()

except:

print("Thread did not start.")

traceback.print_exc()

soc.close()

def client_thread(connection, ip, port, max_buffer_size = 5120):

is_active = True

while is_active:

client_input = receive_input(connection, max_buffer_size)

if "–QUIT–" in client_input:

print("Client is requesting to quit")

connection.close()

print("Connection " + ip + ":" + port + " closed")

is_active = False

else:

print("Processed result: {}".format(client_input))

connection.sendall("-".encode("utf8"))

39
MSIT/ECE/Computer Networking Laboratory/ EC692

def receive_input(connection, max_buffer_size):

client_input = connection.recv(max_buffer_size)

client_input_size = sys.getsizeof(client_input)

if client_input_size>max_buffer_size:

print("The input size is greater than expected {}".format(client_input_size))

decoded_input = client_input.decode("utf8").rstrip() # decode and strip end of line

result = process_input(decoded_input)

return result

def process_input(input_str):

print("Processing the input received from client")

return "Hello " + str(input_str).upper()

if __name__ == "__main__":

main()

Client Code
import socket
import sys

def main():
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "127.0.0.1"
port = 8888

try:
40
MSIT/ECE/Computer Networking Laboratory/ EC692

soc.connect((host, port))
except:
print("Connection error")
sys.exit()

print("Enter 'quit' to exit")


message = input(" -> ")

while message != 'quit':


soc.sendall(message.encode("utf8"))
if soc.recv(5120).decode("utf8") == "-":
pass # null operation

message = input(" -> ")

soc.send(b'quit')

if __name__ == "__main__":
main()

Program 2:

Python Multithreaded Socket Programming has two sections:

 Python Multi Threaded Server Socket Program (Server.py)


 Python Client Socket Program (client.py)

Multithreaded Server Socket Example (server.py)

# import socket programming library


import socket

# import thread module


from _thread import *
import threading

print_lock = threading.Lock()

# thread function
def threaded(c):
while True:

# data received from client


data = c.recv(1024)

41
MSIT/ECE/Computer Networking Laboratory/ EC692

if not data:
print('Bye')

# lock released on exit


print_lock.release()
break

# reverse the given string from client


#data = data[::,]

# send back reversed string to client


c.send(data)

# connection closed
c.close()

def Main():
host = ""

# reverse a port on your computer


# in our case it is 12345 but it
# can be anything
port = 12345
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host, port))
print("socket binded to port", port)

# put the socket into listening mode


s.listen(5)
print("socket is listening")

# a forever loop until client wants to exit


while True:

# establish connection with client


c, addr = s.accept()

# lock acquired by client


print_lock.acquire()
print('Connected to :', addr[0], ':', addr[1])

# Start a new thread and return its identifier


start_new_thread(threaded, (c,))
s.close()

if __name__ == '__main__':
Main()
42
MSIT/ECE/Computer Networking Laboratory/ EC692

Python Socket Client Example(client1.py)

# Import socket module


import socket

def Main():
# local host IP '127.0.0.1'
host = '127.0.0.1'

# Define the port on which you want to connect


port = 12345

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

# connect to server on local computer


s.connect((host,port))

# message you send to server


message = "I am Client-1"
while True:

# message sent to server


s.send(message.encode('ascii'))

# message received from server


data = s.recv(1024)

# print the received message


# here it would be a reverse of sent message
print('Received from the server :',str(data.decode('ascii')))

# ask the client whether he wants to continue


ans = input('\nDo you want to continue(y/n) :')
if ans == 'y':
continue
else:
break
# close the connection
s.close()

if __name__ == '__main__':
Main()

Python Socket Client Example(client2.py)

43
MSIT/ECE/Computer Networking Laboratory/ EC692

# Import socket module


import socket

def Main():
# local host IP '127.0.0.1'
host = '127.0.0.1'

# Define the port on which you want to connect


port = 12345

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

# connect to server on local computer


s.connect((host,port))

# message you send to server


message = "I am Client-2"
while True:

# message sent to server


s.send(message.encode('ascii'))

# message received from server


data = s.recv(1024)

# print the received message


# here it would be a reverse of sent message
print('Received from the server :',str(data.decode('ascii')))

# ask the client whether he wants to continue


ans = input('\nDo you want to continue(y/n) :')
if ans == 'y':
continue
else:
break
# close the connection
s.close()

if __name__ == '__main__':
Main()

5. Discussions & Conclusions:

44
MSIT/ECE/Computer Networking Laboratory/ EC692

6. Area of applications: Knowledge can be applied to understand basic socket programming application in
networking.

7. Question Bank:
 How many types of socket method in python?

 Why do we use sockets in python?

 How do we initialize a socket in python?

8. References:
Data Communications and Networking By Behrouz AForouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

45
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:9
Name of the Experiment: Implementation of Data Link Layer Error Detection Mechanism -Cyclic
Redundancy Check.

Objective: To implement Data Link Layer Error Detection Mechanism -Cyclic Redundancy
Check.[EC692.6]

2. Theory: Error control in data link layer is the process of detecting and correcting data frames that have been
corrupted or lost during transmission. In case of lost or corrupted frames, the receiver does not receive the
correct data-frame and sender is ignorant about the loss. Error Control is a combination of both error detection
and error correction. It ensures that the data received at the receiver end is the same as the one sent by the
sender. Error detection is the process by which the receiver informs the sender about any erroneous frame
(damaged or lost) sent during transmission.
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage
devices to detect accidental changes to digital data. Blocks of data entering these systems get a short check
value attached, based on the remainder of a polynomial division of their contents.
CRC or Cyclic Redundancy Check is a method of detecting accidental changes/errors in the communication
channel. CRC uses Generator Polynomial which is available on both sender and receiver sides. An example
generator polynomial is of the form of x^3 + 1. This generator polynomial represents key 1001. Another
example is x^2 + x. that represents key 110.

3. Requirement:

Apparatus:

 P.C
 Internet
 Python Software

4. Results & Simulation:


Program:
# SERVER_CRC:

import socket

def xor(a, b):

# initialize result
46
MSIT/ECE/Computer Networking Laboratory/ EC692

result = []

# Traverse all bits, if bits


are
# same, then XOR is 0, else 1
for i in range(1, len(b)):
if a[i] == b[i]:
result.append('0')
else:
result.append('1')

return''.join(result)

# Performs Modulo-2 division


def mod2div(divident, divisor):

# Number of bits to be XORed at


a time.
pick = len(divisor)

# Slicing the divident to


appropriate
# length for particular step
tmp = divident[0 : pick]

while pick <len(divident):

if tmp[0] =='1':

# replace the divident


by the result
# of XOR and pull 1 bit
down
tmp = xor(divisor, tmp) +
divident[pick]

else: # If leftmost bit


is'0'

# If the leftmost bit


of the dividend (or the
# part used in each
step) is 0, the step cannot
# use the regular
divisor; we need to use an
# all-0s divisor.
tmp = xor('0'*pick, tmp) +
divident[pick]

# increment pick to move


further
pick += 1

47
MSIT/ECE/Computer Networking Laboratory/ EC692

# For the last n bits, we have


to carry it out
# normally as increased value
of pick will cause
# Index Out of Bounds.
if tmp[0] =='1':
tmp = xor(divisor, tmp)
else:
tmp = xor('0'*pick, tmp)

checkword = tmp
return checkword

# Function used at the sender side


to encode
# data by appending remainder of
modular division
# at the end of data.
def encodeData(data, key):

l_key = len(key)

# Appends n-1 zeroes at end of


data
appended_data = data +'0'*(l_key-1)
remainder =
mod2div(appended_data, key)

# Append remainder in the


original data
codeword = data + remainder
return codeword

# Create a socket object


s = socket.socket()

# Define the port on which you want


to connect
port = 12345

# connect to the server on local


computer
s.connect(('127.0.0.1', port))

# Send data to server'Hello world'

## s.sendall('Hello World')

input_string = input("Enter data


you want to send->")
#s.sendall(input_string)
data =(''.join(format(ord(x),'b')

48
MSIT/ECE/Computer Networking Laboratory/ EC692

for x in input_string))
print("Entered data in binary
format :",data)
key ="1001"

ans = encodeData(data,key)
print("Encoded data to be sent to
server in binary format :",ans)
s.sendto(ans.encode(),('127.0.0.1',
12345))

# receive data from the server


print("Received feedback from
server :",s.recv(1024).decode())

# close the connection


s.close()

# CLIENT_CRC:-

import socket

def xor(a, b):

# initialize result
result = []

# Traverse all bits, if bits


are
# same, then XOR is 0, else 1
for i in range(1, len(b)):
if a[i] == b[i]:
result.append('0')
else:
result.append('1')

return''.join(result)

# Performs Modulo-2 division


def mod2div(divident, divisor):

# Number of bits to be XORed at


a time.
pick = len(divisor)

# Slicing the divident to


appropriate
# length for particular step
tmp = divident[0: pick]
49
MSIT/ECE/Computer Networking Laboratory/ EC692

while pick <len(divident):

if tmp[0] =='1':

# replace the divident


by the result
# of XOR and pull 1 bit
down
tmp = xor(divisor, tmp) +
divident[pick]

else: # If leftmost bit


is'0'
# If the leftmost bit
of the dividend (or the
# part used in each
step) is 0, the step cannot
# use the regular
divisor; we need to use an
# all-0s divisor.
tmp = xor('0'*pick, tmp) +
divident[pick]

# increment pick to move


further
pick += 1

# For the last n bits, we have


to carry it out
# normally as increased value
of pick will cause
# Index Out of Bounds.
if tmp[0] =='1':
tmp = xor(divisor, tmp)
else:
tmp = xor('0'*pick, tmp)

checkword = tmp
return checkword

# Function used at the receiver


side to decode
# data received by sender

def decodeData(data, key):

l_key = len(key)

# Appends n-1 zeroes at end of


data
appended_data = data.decode()

50
MSIT/ECE/Computer Networking Laboratory/ EC692

+'0'*(l_key-1)
remainder =
mod2div(appended_data, key)

return remainder

# Creating Socket
s = socket.socket()
print("Socket successfully
created")

# reserve a port on your computer


in our
# case it is 12345 but it can be
anything
port = 12345

s.bind(('', port))
print("socket binded to %s"%
(port))
# put the socket into listening
mode
s.listen(5)
print("socket is listening")

while True:
# Establish connection with
client.
c, addr = s.accept()
print('Got connection from',
addr)

# Get data from client


data = c.recv(1024)

print("Received encoded data in


binary format :", data.decode())

if not data:
break

key ="1001"

ans = decodeData(data, key)


print("Remainder after decoding
is->"+ans)

# If remainder is all zeros


then no error occured
temp ="0"* (len(key) - 1)
if ans == temp:

51
MSIT/ECE/Computer Networking Laboratory/ EC692

c.sendto(("THANK you Data -


>"+data.decode() +
"Received No error
FOUND").encode(), ('127.0.0.1',
12345))
else:
c.sendto(("Error in
data").encode(), ('127.0.0.1',
12345))

c.close()

5. Discussions & Conclusions:

6.Area of Application:Knowledge can be applied to understand Data link layer error detection mechanism.

7. Question Bank:
 Which layer is responsible for CRC?
 What is the purpose of CRC?
 Which protocols use CRC?

8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

52
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name:Computer Networking laboratory
Course Code: EC692

Experiment No:10
Name of the Experiment: Implementation of Data Link Layer Flow control Mechanism.

Objective: To implement Data Link Layer Flow control mechanism. [EC692.5]

Problem Statement:
Write the program of Sender and Receiver using socket program to implement the sliding window feature. The
Program will implement the Go Back N ARQ or the Selective Repeat ARQ. It will send an acknowledgement
whenever the program will receive the binary bit. Then if the acknowledgement is not received by the sender it
will retransmit the whole frame.
Language Used - Python

2. Theory:The two codes Sender and Receiver are the implementation of Go Back N ARQ protocol of
networking and based on the Sliding Window Protocol concept.Go Back N ARQ which stands for Go Back N
Automatic Repeat Request (ARQ) is a data link layer protocol that is used for data flow control purposes. It is
a sliding window protocol in which multiple frames are sent from sender to receiver at once. The number of
frames that are sent at once depends upon the size of the window that is taken. It will convert the inputted
message in the sender into binary and then ask for the window size. It will then send bit by bit to the receiver
which will then send the acknowledgement back to the sender. The sender can simulate whether the packet will
be lost or received and will retransmit if the acknowledgment is lost. If the acknowledgement is not lost then the
next bit is sent to the receiver. This process will continue until the entire message is received.

Fig. 10.1 The GO-BACK-N ARQ Flow Control Mechanism

53
MSIT/ECE/Computer Networking Laboratory/ EC692

3. Requirement:

Apparatus:

 P.C
 Internet
 Python Software

4.Result & Simulation:


Program:
SENDER_GO_BACK_N:-

# Sender.py
import time, socket, sys

def decimalToBinary(n):
return n.replace("0b", "")

def binarycode(s):
a_byte_array = bytearray(s, "utf8")

byte_list = []

for byte in a_byte_array:


binary_representation = bin(byte)
byte_list.append(decimalToBinary(binary_representation))

#print(byte_list)
a=""
for i in byte_list:
a=a+i
return a

print("\nWelcome to Chat Room\n")


print("Initialising....\n")
time.sleep(1)

s = socket.socket()
host = socket.gethostname()
ip = socket.gethostbyname(host)
port = 1234
s.bind((host, port))
print(host, "(", ip, ")\n")
name = input(str("Enter your name: "))

s.listen(1)
print("\nWaiting for incoming connections...\n")
conn, addr = s.accept()
print("Received connection from ", addr[0], "(", addr[1], ")\n")

54
MSIT/ECE/Computer Networking Laboratory/ EC692

s_name = conn.recv(1024)
s_name = s_name.decode()
print(s_name, "has connected to the chat room\nEnter [e] to exit chat room\n")
conn.send(name.encode())

while True:
message = input(str("Me : "))
conn.send(message.encode())
if message == "[e]":
message = "Left chat room!"
conn.send(message.encode())
print("\n")
break
message=binarycode(message)
f=str(len(message))
conn.send(f.encode())

i=0
j=0
j=int(input("Enter the window size -> "))

b=""

j=j-1
f=int(f)
k=j
while i!=f:
while(i!=(f-j)):
conn.send(message[i].encode())
b=conn.recv(1024)
b=b.decode()
print(b)
if(b!="ACK Lost"):
time.sleep(1)
print("Acknowledgement Received! The sliding window is in the range
"+(str(i+1))+" to "+str(k+1)+" Now sending the next packet")
i=i+1
k=k+1
time.sleep(1)
else:
time.sleep(1)
print("Acknowledgement of the data bit is LOST! The sliding window remains in the
range "+(str(i+1))+" to "+str(k+1)+" Now Resending the same packet")
time.sleep(1)
while(i!=f):

conn.send(message[i].encode())
b=conn.recv(1024)
b=b.decode()
print(b)
if(b!="ACK Lost"):
time.sleep(1)

55
MSIT/ECE/Computer Networking Laboratory/ EC692

print("Acknowledgement Received! The sliding window is in the range


"+(str(i+1))+" to "+str(k)+" Now sending the next packet")
i=i+1
time.sleep(1)
else:
time.sleep(1)
print("Acknowledgement of the data bit is LOST! The sliding window remains in the
range "+(str(i+1))+" to "+str(k)+" Now Resending the same packet")
time.sleep(1)

RECEIVER_GO_BACK_N:-

# Receiver.py
import time, socket, sys
import random

print("\nWelcome to Chat Room\n")


print("Initialising....\n")
time.sleep(1)

s = socket.socket()
shost = socket.gethostname()
ip = socket.gethostbyname(shost)
print(shost, "(", ip, ")\n")
host = input(str("Enter server address: "))
name = input(str("\nEnter your name: "))
port = 1234
print("\nTrying to connect to ", host, "(", port, ")\n")
time.sleep(1)
s.connect((host, port))
print("Connected...\n")

s.send(name.encode())
s_name = s.recv(1024)
s_name = s_name.decode()
print(s_name, "has joined the chat room\nEnter [e] to exit chat room\n")

while True:

m=s.recv(1024)
m=m.decode()
k=s.recv(1024)
k=k.decode()
k=int(k)
i=0
a=""
b=""
f=random.randint(0,1)
message=""
56
MSIT/ECE/Computer Networking Laboratory/ EC692

while i!=k:

f=random.randint(0,1)
if(f==0):
b="ACK Lost"
message = s.recv(1024)
message = message.decode()
s.send(b.encode())

elif(f==1):
b="ACK "+str(i)
message = s.recv(1024)
message = message.decode()

s.send(b.encode())
a=a+message
i=i+1

print("The message received is :", m)

5. Discussion &Conclusion:

6. Area of Application:Knowledge can be applied to understand basics of data link layer in the field of
networking.

7. Question Bank:
 Describe the Go Back N ARQ Protocol.
 What is the window size in Go Back N ARQ?
 Go Back N ARQ works on which prescribe mechanism?

8. References:
Data Communications and Networking By Behrouz AForouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

57
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:11
Name of the Experiment: To find system date and time using Socket Programming.

Objective: To implement the knowledge of Socket Programming to get the current date and time.
[EC692.3]

2. Theory: In this experiment, we will learn How to get the current Date and Time using Python Socket
Programming. In Python, date and time are not data types of their own, but a module that can be imported to
work with the date as well as time.
3. Requirement:

Apparatus:

 P.C
 Internet
 Python Software

4. Results & Simulation:

Program:
Server code

# server.py
import socket
import time

# create a socket object


serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)

# get local machine name


host = socket.gethostname()

port = 9999

# bind to the port


serversocket.bind((host, port))

58
MSIT/ECE/Computer Networking Laboratory/ EC692

# queue up to 5 requests
serversocket.listen(5)

while True:
# establish a connection
clientsocket,addr = serversocket.accept()

print("Got a connection from %s" % str(addr))


currentTime = time.ctime(time.time()) + "\r\n"
clientsocket.send(currentTime.encode('ascii'))
clientsocket.close()

client code

# client.py
import socket

# create a socket object


s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# get local machine name


host = socket.gethostname()

port = 9999

# connection to hostname on the port.


s.connect((host, port))

# Receive no more than 1024 bytes


tm = s.recv(1024)

s.close()

print("The time got from the server is %s" % tm.decode('ascii'))

5. Discussions & Conclusions:

6. Area of applications: Knowledge can be applied to understand application of socket Programming.

7. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidhu
Python Programming by Reema Thereja
Core Python Programming By Dr. R.Nageswara Rao

59
MSIT/ECE/Computer Networking Laboratory/ EC692

MEGHNAD SAHA INSTITUTE OF TECHNOLOGY


Department of Electronics and Communication Engineering
Laboratory Manual
Course Name: Computer Networking laboratory
Course Code: EC692

Experiment No:12

Name of the Experiment: Building a Network Topologies with Cisco Packet Tracer.

Objective: To learn about configure a different networks in cisco packet tracer.

2. Theory: Packet Tracer is a proprietary tool of Cisco. It is used to create & simulate network virtually.
It gives same environment virtually as it exists physically.
This tool gives all type of network devices require to create one real time working network and also
provide same interface as on real device.

Packet Tracer has two different views


 Logical Workspace
 Physical Workspace
Packet Tracer also has two modes of operation
 Real-time Mode
 Simulation Mode

3. Requirement:

Apparatus:

 P.C
 Internet
 Cisco Packet Tracer Student 6.2 program.

4. Procedure:
60
MSIT/ECE/Computer Networking Laboratory/ EC692

Fig12.1

Fig. 12.1 shows the different tools used in CISCO packet Tracer as end devices,routers, switches, hubs,
cables, …etc.

1. Built a simple network topology with just two PCs as shown in fig 12.2 by Selecting “End Devices”
and click at “Generic” and click on the main area. Repeat it to the second device.

Fig12.2
2.Select “Connections” from Power Cycle Devices and click on “Copper Cross-Over”, - two end devices
needs a cross-over connection in-between - , then draw connections from the first NIC (Ethrnet0)of PC0
to the second NIC (Ethrnet0) PC1as shown in fig 12.3.

Fig12.3
3.Double click on a PC, a box will appear. Click on the “Desktop” tab, then select “IP configuration” ,
Write the IP address of your network and click at the Subnet mask filed. Subnet Mask will appear
automatically. Repeat it to set the IPs for all the PCs.
By using "Place Note" Tool, write the IP address for each device under it.

61
MSIT/ECE/Computer Networking Laboratory/ EC692

Fig12.4
4.Double click on a PC0, a box will appear. Click on the “Desktop” tab, then select “Command
Prompt” , write "PC>ping 10.0.0.2" , if there is a reply lik e fig 1 2.5 then the connection is
successful.

Fig12.5

Do the previous step by following steps:

1.Select “Add simple PDU” as shown in fig 12.6.

Fig12.6

2. Drag and Drop the message to the source device and then to the Destination device. In this case my
source device is PC0 and destination device is PC1.
3. Select the Simulation Mode at the bottom right corner as shown in fig12.7.

Fig12.7

4. Click at “Auto Capture / Play”.


5. Observe the path of the Message from source to destination, and back from the destination to the
source as shown in fig 12.8.

62
MSIT/ECE/Computer Networking Laboratory/ EC692

Fig12.8

6. Finally observe the marks. If the source PC is marked correct it means you have successfully
established the connection.

After these steps, repeat them with Finally observe the marks. If the source PC is marked correct it
means you have successfully established the connection.

Fig12.9

When use Hub and try to send a simple PDU from a source device to a destination device,the path of the
Message was from source to Hub, then to all devices. And then from Destination to Hub then back to the
source with the same procedure.
The Switch was the same at the first, but it has a learning attribute that let it build a table contains of MAC
address and IP address for each end device that connect to it, so after the first message between two
devices, it doesn't send the message to all devices, but to the destination device directly.

63
MSIT/ECE/Computer Networking Laboratory/ EC692

5.Discussions & Conclusions:

6. Area of applications: Knowledge can be applied to understand application of Networking.

7. Question Banks:

 Explain the forwarding method in switch.


 Name some layer 2 devices
 Difference between layer 2 and layer 3 devices.

8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidh

64
65

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy