CN Lab Manual Total (EC692)
CN Lab Manual Total (EC692)
COMPUTER NETWORKING
LABORATORY MANUAL
B.TECH
(3rd Year–2nd Sem)
Version: 1.1
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
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.
4
MSIT/ECE/ Computer Networking Laboratory /EC692
5
MSIT/ECE/ Computer Networking Laboratory /EC692
6
MSIT/ECE/ Computer Networking Laboratory /EC692
Objective:
To Learn and Understand basic Computer networking Concepts.
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
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
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
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
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.
7. Pen drive is not allowed. Shut down the computers and switch off after completion of
Experiments.
10
MSIT/ECE/Computer Networking Laboratory/EC692
• Familiarization with
Hubs, Switches
• Implementation of
Data Link Layer Flow Control Mechanism (Stop & Wait, Sliding Window)
11
MSIT/ECE/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.
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
13
MSIT/ECE/Computer Networking Laboratory/ EC692
Experiment No:1
Name of the Experiment: Installation & Configuration of NIC.
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.
Procedure:
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:
15
MSIT/ECE/Computer Networking Laboratory/ EC692
7. Question Banks:
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
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.
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.
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.
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.
19
MSIT/ECE/Computer Networking Laboratory/ EC692
7. Question Banks:
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
Experiment No:3
Name of the Experiment: Introduction to 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
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)
val='hello'
print(val)
21
MSIT/ECE/Computer Networking Laboratory/ EC692
val=100
print(val)
val=12.34
print(val)
str='Hello'
print(str+'4')
print(str*5)
my_tuple=(1,2,3,4,5,6,7,8)
print(my_tuple[1:4])
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 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)
def add(a,b):
sum1=a+b
return sum1
print("sum1",add(5,6))
def total(a,b):
result=a+b
23
MSIT/ECE/Computer Networking Laboratory/ EC692
#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')
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
Experiment No:4
Name of the Experiment: Inter-process communication using Message Queue.
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.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
import multiprocessing
import time
import random
def produce(q):
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')
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
Experiment No:5
Name of the Experiment: Introduction to Socket Programming.
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
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
url="https://api.time.com/wp-content/uploads/2018/03/gettyimages-932825264.jpg"
download=urllib.request.urlretrieve(url, "image.jpg")
Program3:
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()
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
Experiment No:6
Name of the Experiment: Implementation of TCP Socket Programming.
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
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()
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?
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
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
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
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()
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
Experiment No:8
Name of the Experiment: Implementation of a Prototype Multithreaded Server.
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
Program 1:
Server Code
import socket
import sys
import traceback
37
MSIT/ECE/Computer Networking Laboratory/ EC692
def main():
start_server()
def start_server():
host = "127.0.0.1"
print("Socket created")
try:
soc.bind((host, port))
except:
sys.exit()
while True:
try:
except:
traceback.print_exc()
soc.close()
is_active = True
while is_active:
if "–QUIT–" in client_input:
connection.close()
is_active = False
else:
connection.sendall("-".encode("utf8"))
39
MSIT/ECE/Computer Networking Laboratory/ EC692
client_input = connection.recv(max_buffer_size)
client_input_size = sys.getsizeof(client_input)
if client_input_size>max_buffer_size:
result = process_input(decoded_input)
return result
def process_input(input_str):
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()
soc.send(b'quit')
if __name__ == "__main__":
main()
Program 2:
print_lock = threading.Lock()
# thread function
def threaded(c):
while True:
41
MSIT/ECE/Computer Networking Laboratory/ EC692
if not data:
print('Bye')
# connection closed
c.close()
def Main():
host = ""
if __name__ == '__main__':
Main()
42
MSIT/ECE/Computer Networking Laboratory/ EC692
def Main():
# local host IP '127.0.0.1'
host = '127.0.0.1'
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
if __name__ == '__main__':
Main()
43
MSIT/ECE/Computer Networking Laboratory/ EC692
def Main():
# local host IP '127.0.0.1'
host = '127.0.0.1'
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
if __name__ == '__main__':
Main()
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?
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
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
import socket
# initialize result
46
MSIT/ECE/Computer Networking Laboratory/ EC692
result = []
return''.join(result)
if tmp[0] =='1':
47
MSIT/ECE/Computer Networking Laboratory/ EC692
checkword = tmp
return checkword
l_key = len(key)
## s.sendall('Hello World')
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))
# CLIENT_CRC:-
import socket
# initialize result
result = []
return''.join(result)
if tmp[0] =='1':
checkword = tmp
return checkword
l_key = len(key)
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")
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)
if not data:
break
key ="1001"
51
MSIT/ECE/Computer Networking Laboratory/ EC692
c.close()
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
Experiment No:10
Name of the Experiment: Implementation of Data Link Layer Flow control Mechanism.
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.
53
MSIT/ECE/Computer Networking Laboratory/ EC692
3. Requirement:
Apparatus:
P.C
Internet
Python Software
# Sender.py
import time, socket, sys
def decimalToBinary(n):
return n.replace("0b", "")
def binarycode(s):
a_byte_array = bytearray(s, "utf8")
byte_list = []
#print(byte_list)
a=""
for i in byte_list:
a=a+i
return a
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
RECEIVER_GO_BACK_N:-
# Receiver.py
import time, socket, sys
import random
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
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
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
Program:
Server code
# server.py
import socket
import time
port = 9999
58
MSIT/ECE/Computer Networking Laboratory/ EC692
# queue up to 5 requests
serversocket.listen(5)
while True:
# establish a connection
clientsocket,addr = serversocket.accept()
client code
# client.py
import socket
port = 9999
s.close()
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
Experiment No:12
Name of the Experiment: Building a Network Topologies with 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.
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
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
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
7. Question Banks:
8. References:
Data Communications and Networking By Behrouz A Forouzan.
An Integrated Approach to Computer Networks by Bhavneet Sidh
64
65