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

Computer Networks Practical File Taruna Gupta 22BCE11551

The document is a practical record for the course CSE3006-Computer Networks submitted by Taruna Gupta at VIT Bhopal University for the academic year 2024-2025. It includes various experiments related to networking concepts, socket programming, and Linux commands, detailing aims, algorithms, procedures, and results of each experiment. The record affirms originality and compliance with university regulations.

Uploaded by

tarunagupta2218
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)
31 views65 pages

Computer Networks Practical File Taruna Gupta 22BCE11551

The document is a practical record for the course CSE3006-Computer Networks submitted by Taruna Gupta at VIT Bhopal University for the academic year 2024-2025. It includes various experiments related to networking concepts, socket programming, and Linux commands, detailing aims, algorithms, procedures, and results of each experiment. The record affirms originality and compliance with university regulations.

Uploaded by

tarunagupta2218
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

VIT Bhopal University,

Bhopal-Indore Highway
Kothrikalan,
Sehore,
Madhya Pradesh - 466114

DEPARTMENT OF COMPUTING SCIENCE AND


ENGINEERING

ACADEMIC YEAR: 2024-2025

WINTER SEMESTER 2024 – 2025

Submitted By

Taruna Gupta
Reg No: 22BCE11551

Submitted to

Dr. M. Manimaran,
Senior Assistant Professor,

School of Computing Science Engineering,


I Taruna Gupta, hereby declare that the practical record titled CSE3006-COMPUTER

NETWORKS is my original work and has been completed under the guidance of

Dr.M.Manimaran during the academic year 2024-2025.

I affirm that this record has not been submitted elsewhere and complies with the rules and

regulations of VIT BHOPAL UNIVERSITY.

Date: 25th March, 2025

Name of the Student: Taruna Gupta


Reg Number: 22BCE11551

Faculty Signature
Index

E.NO DATE EXPERIMENT NAME PG.NO. FACULT


Y SIGN
Demo session of all networking hardware and Functionalities 3
1 24/01/2025

Introduction to Socket Programming, Basic Linux Commands 6


2 31/01/2025

9
3 07/02/2025 To study various types of Connectors

12
4 14/02/2025 LAN installations and their Configuration

5 28/02/2025 To implement various type of error correcting techniques. 17


20
6 13/03/2025 To implement various types of DLL protocols.

Imagine two processes communicate across a network. 24


One process running in your
local system is web browser and the other process running in the
7 remote system is
25/03/2025 the web server. Once a connection is established between the web
browser and web
server, the server’s current date and time has to be displayed in
web browser. Write
a suitable program for this scenario.

A network communication model is created by establishing 28


connection between a
client and a server. The connection is also guaranteed by transferring
8 28/03/2025 client’s IP
address to the server and displays it in the server’s premises.
Write a program for the
above situation.
Consider two processes client and server communicates across a 31
network. The client
9 01/04/2025 sends a message to the server in the request and the server responds
with the same
message. Write a Socket program for the above mentioned
scenario.

34
10 04/04/2025 To study various TCL commands.

36
The message entered in the client is sent to the server and the
11 11/04/2025 server encodes the message and returns it to the client. Encoding is
done by replacing a character by the character next to it (i.e.) a as
b, b as c…z as a.

Packet Tracer: Observing Packets across the network and 39


12 18/04/2025 Performance Analysis of
Routing protocols
Ex. No: 1
Demo session of all networking hardware and Functionalities.
Date:

AIM:

A demo session of networking hardware and functionalities

ALGORITHM:

1) Start
2) Create Devices with name, MAC address, and IP address.
3) Hub Function:
a) Connect devices.
b) On data send → broadcast to all devices except sender.
4) Switch Function:
a) Store MAC addresses of connected devices.
b) On data send → forward only to device with matching MAC.
5) Router Function:
a) Store IP addresses of connected devices.
b) On data send → route to the device with matching IP.
6) Access Point Function:
a) Connect devices wirelessly.
b) On data send → share with all connected devices.
7) Modem Function:
a) Transmit: Convert data to binary (simulate analog signal).
b) Receive: Convert binary back to original data.
8) Display Results of sending and receiving through each device.
9) End

PROGRAM:

class Device:
def __init__(self, name, mac, ip=None):
self.name = name
self.mac = mac
self.ip = ip

def receive_data(self, data):


print(f"{self.name} received: {data}")

# Hub: Broadcasts to all devices


class Hub:
def __init__(self):
self.devices = []

def connect(self, device):


self.devices.append(device)

def send(self, sender, data):


print(f"\n[Hub] Broadcasting data from {sender.name}")
for device in self.devices:
if device != sender:
device.receive_data(data)

# Switch: Sends only to the destination MAC


class Switch:
def __init__(self):
self.mac_table = {}

def connect(self, device):


self.mac_table[device.mac] = device

def send(self, sender, dest_mac, data):


print(f"\n[Switch] Routing data from {sender.name} to MAC {dest_mac}")
if dest_mac in self.mac_table:
self.mac_table[dest_mac].receive_data(data)
else:
print("MAC address not found.")

# Router: Connects different IP networks


class Router:
def __init__(self):
self.routing_table = {}

def connect(self, device):


self.routing_table[device.ip] = device

def send(self, sender, dest_ip, data):


print(f"\n[Router] Forwarding data from {sender.ip} to {dest_ip}")
if dest_ip in self.routing_table:
self.routing_table[dest_ip].receive_data(data)
else:
print("IP not reachable.")

# Access Point: Bridges wireless devices to wired network


class AccessPoint:
def __init__(self):
self.connected_devices = []
def connect(self, device):
self.connected_devices.append(device)
print(f"{device.name} connected to Access Point wirelessly.")

def send(self, sender, data):


print(f"\n[Access Point] Sending data from {sender.name}")
for device in self.connected_devices:
if device != sender:
device.receive_data(data)

# Modem: Just a dummy digital/analog converter (simulated)


class Modem:
def transmit(self, data):
analog_signal = ''.join(format(ord(c), '08b') for c in data)
print(f"\n[Modem] Transmitting analog signal: {analog_signal}")
return analog_signal

def receive(self, analog_signal):


chars = [chr(int(analog_signal[i:i+8], 2)) for i in range(0, len(analog_signal), 8)]
data = ''.join(chars)
print(f"[Modem] Received digital data: {data}")
return data

# ---------- DEMO ----------


deviceA = Device("PC-A", "AA:BB:CC:01", "192.168.1.2")
deviceB = Device("PC-B", "AA:BB:CC:02", "192.168.1.3")
deviceC = Device("PC-C", "AA:BB:CC:03", "10.0.0.5")

print("\n--- HUB Demo ---")


hub = Hub()
hub.connect(deviceA)
hub.connect(deviceB)
hub.connect(deviceC)
hub.send(deviceA, "Hello from A!")

print("\n--- SWITCH Demo ---")


switch = Switch()
switch.connect(deviceA)
switch.connect(deviceB)
switch.connect(deviceC)
switch.send(deviceA, "AA:BB:CC:02", "Private message to B")

print("\n--- ROUTER Demo ---")


router = Router()
router.connect(deviceA)
router.connect(deviceC)
router.send(deviceA, "10.0.0.5", "Data to other network")

print("\n--- ACCESS POINT Demo ---")


ap = AccessPoint()
ap.connect(deviceA)
ap.connect(deviceB)
ap.send(deviceA, "Wi-Fi broadcast!")

print("\n--- MODEM Demo ---")


modem = Modem()
signal = modem.transmit("Internet Data")
modem.receive(signal)

OUTPUT:

--- HUB Demo ---

[Hub] Broadcasting data from PC-A


PC-B received: Hello from A!
PC-C received: Hello from A!

--- SWITCH Demo ---

[Switch] Routing data from PC-A to MAC AA:BB:CC:02


PC-B received: Private message to B

--- ROUTER Demo ---

[Router] Forwarding data from 192.168.1.2 to 10.0.0.5


PC-C received: Data to other network

--- ACCESS POINT Demo ---


PC-A connected to Access Point wirelessly.
PC-B connected to Access Point wirelessly.

[Access Point] Sending data from PC-A


PC-B received: Wi-Fi broadcast!

--- MODEM Demo ---

[Modem] Transmitting analog signal:


010010010110111001110100011001010111001001101110011001010111010000100000010001
00011000010111010001100001
[Modem] Received digital data: Internet Data
RESULT:

· Understand the Role of Each Networking Device

Differentiate between routers, switches, modems, access points, and firewalls.

Recognize their specific functions in a network.

· Set Up a Basic Network

Successfully connect a modem, router, and switch to establish a wired and wireless
network.

Assign IP addresses (static and dynamic) for devices.

· Configure and Secure a Network

Implement MAC address filtering and firewall rules.

Understand basic security measures like encryption and access control.

· Perform Network Troubleshooting

Identify and resolve common connectivity issues.

Use tools like ping, tracert, and Wireshark to diagnose network problems.

· Understand Advanced Networking Concepts

VLAN setup for network segmentation.

Port forwarding for remote access to services.

Monitoring network traffic for security and optimizatio


Ex. No: 2
Introduction to Socket Programming, Basic Linux Commands
Date:

AIM:

Introduction to Socket Programming, Basic Linux Commands

ALGORITHM:

Part 1: Socket Programming (Client-Server Model)


1. Start
2. Import socket module in your program.
3. For Server:
o Create a socket using socket().
o Bind it to an IP address and port using bind().
o Listen for connections using listen().
o Accept connection using accept().
o Receive data from client.
o Send response back to client (optional).
o Close connection.
4. For Client:
o Create a socket using socket().
o Connect to server using connect().
o Send message to server.
o Receive response from server (optional).
o Close connection.
5. End

Part 2: Basic Linux Commands


1. Start
2. Learn and use the following essential commands:
o pwd → Show current directory.
o ls → List files and directories.
o cd → Change directory.
o mkdir → Make new directory.
o touch → Create a new file.
o cp, mv, rm → Copy, move, and delete files.
o cat, nano, vim → View or edit files.
o chmod, chown → Change file permissions and ownership.
o ifconfig, ping → Check network settings and connectivity.
o ps, top → Monitor processes.
3. Try these commands on a terminal to practice.
4. End
PROGRAM:

Basic Soket programming:


OUTPUT:

If no client connects, the server keeps waiting:

If error occurs:

Basic Linux commands:

File directory commands

command description example

ls List files and directories ls -l (detailed view)

pwd Show current directory pwd

cd Change directory cd /home/user

mkdir Create a new directory Mkdir myfolder

rmdir Remove empty directory rmdir myfolder


RESULT:

Socket Programming Results

✅Understand the concept of sockets, TCP vs. UDP, and client-server


communication.
✅Successfully implement a basic TCP server and client in C++
✅Establish a working network connection between a client and server.
✅Send and receive messages between devices using sockets.
✅Debug and handle common networking issues like port binding
errors and connection timeouts.

Basic Linux Commands Results

✅List and navigate directories using ls, cd, and pwd.


✅Manage files using touch, cat, rm, cp, and mv.
✅Monitor system processes with ps, top, and kill.
✅Test network connectivity with ping, ifconfig/ip a, and netstat.
✅Securely manage users and permissions with who, chmod, and chown.
Ex. No: 3
To study various types of Connectors
Date:

AIM OF THE EXPERIMENT:

The aim of this experiment is to establish a peer-to-peer connection between two computers using
a network simulation tool (Cisco Packet Tracer) and identify their IP addresses, MAC addresses,
and observe packet transfer between the end devices.

PROCEDURE:
44
1. Set up network simulation tool and create a virtual network environment.
2. Add two computer to the network topology and establish connection between the two computer
using Ethernet cables or virtual connections.
3. Assign IP addresses to each computer in the same subnet.
4. Use various commands to identify and note down the MAC addresses of both computers.
5. Configure the network settings of each computer to ensure they can communicate with each
other.
6. Monitor andobserve the packet transfer between the end devices.
7. Analyze the network traffic to identify the IP addresses, and successful packet transfers.

DESCRIPTION:
In computer networks, a peer-to-peer connection refers to a direct communication link between the
devices without the need for an intermediary server. IP addresses are unique numerical identifiers
assigned to each device on a network, allowing them to send and receive data. MAC addresses are
physical addresses that are permanently assigned to network interface cards (NICs) and serve as
unique identifiers at the data link layer

PROGRAM:

Commands Used:
• ipconfig
• ipconfig /all
• ping

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class ConnectorExample {

public static void main(String[] args) {


// MySQL Connection
String mysqlUrl = "jdbc:mysql://localhost:3306/testdb";
String mysqlUser = "root";
String mysqlPass = "password";
// SQLite Connection
String sqliteUrl = "jdbc:sqlite:test.db";

try {
// MySQL Connector
System.out.println("Connecting to MySQL...");
Connection mysqlConn = DriverManager.getConnection(mysqlUrl, mysqlUser,
mysqlPass);
Statement mysqlStmt = mysqlConn.createStatement();
ResultSet mysqlRs = mysqlStmt.executeQuery("SELECT * FROM users");

while (mysqlRs.next()) {
System.out.println("MySQL User: " + mysqlRs.getString("username"));
}
mysqlConn.close();

// SQLite Connector
System.out.println("\nConnecting to SQLite...");
Connection sqliteConn = DriverManager.getConnection(sqliteUrl);
Statement sqliteStmt = sqliteConn.createStatement();
ResultSet sqliteRs = sqliteStmt.executeQuery("SELECT * FROM users");

while (sqliteRs.next()) {
System.out.println("SQLite User: " + sqliteRs.getString("username"));
}
sqliteConn.close();

} catch (Exception e) {
e.printStackTrace();
}
}
}

OBSERVATION:

During the experiment, the following observations were made:


• The IP addresses of the two computers were successfully assigned and configured in the same
subnet.
• The MAC addresses of both computers were identified and noted down.
• The peer-to-peer connection was established between the two computers using Ethernet cables
or virtual connections.
• Network traffic was monitored, and packet transfers between the end devices were observed.
• Successful packet transfers were recorded, indicating the successful communication between
the two computers.
o MAC Address for PC0- 0060.3E7C.E8CD
o MAC Address for PC1- 00E0.F731.6DEA

OUTPUT:

1.Virtual Network Environment

2. Assigned IP address to PC0 and PC1-

3. Ipconfig on PC0-
4. Ipconfig on PC1-

5. Ipconfig /all on PC0-


6. Ip config /all on PC1-

7. Ping (PC1 IP address) on PC0-


8. Ping (PC0 IP address) on PC1-

9. Packet Transfer-
RESULT:

Based on the observations made during the experiment, the following conclusions can be drawn:
• The network simulation tool effectively facilitated the establishment of a peer-to-peer
connection between two computers.
• The IP addresses assigned to the computers allowed them to communicate with each other
within the same subnet.
• The MAC addresses uniquely identified each computer at the data link layer.
• The successful packet transfers confirmed the successful communication between the two
computers.
• This experiment provided a practical understanding of network connectivity. IP addressing,
MAC addressing and packet transfer in a simulated network environment.

Overall, the experiment successfully demonstrated the process of establishing a peer-to-peer


connection, identifying IP and MAC addresses, and observing packet transfer between end
devices using a network simulation tool. It highlights the importance of accurate addressing and
effective communication protocols for network connectivity. The knowledge gained from this
experiment can be applied to a real-world network configurations and troubleshooting scenarios.
Ex. No: 4
LAN installations and their Configuration
Date:

AIM:

LAN installations and their Configuration

THEORY:

A Local Area Network (LAN) is a network that connects multiple devices within a limited area,
such as a home, office, or school. LAN installation involves hardware setup, configuration, and
security measures to ensure efficient communication between device.

PROCEDURES:

Setting up the LAN:

Determine the number of computers you want to connect. The number


of computers you're connecting will determine the type of network
hardware you'll need.

If you are connecting four or fewer computers, you'll just need a single router, or
one switch if you don't need internet.
If you're connecting more than four computers, you'll want a router and a switch,
or just a switch if you don't need internet.
Obtain the network hardware. To create a LAN, you'll need a router and/or a network. These
pieces of hardware are the "hub" of your LAN, and all of your computers will be connected to
them.

Connect your modem to the WAN port on the router. This port may be labeled "INTERNET"
instead. This will provide internet access to every computer that is connected to your LAN.
You can skip this if you're setting up a LAN without internet access.You don't need a router at all
to create a LAN, but it makes things easier. If you just use a network switch, you'll need to
manually assign IP addresses to each computer after connecting them.
Connect the switch to a LAN port on the router. If you're using a network switch to
connect more computers, connect it to one of the LAN ports on the router. You can
use any open port on the switch to make the connection. When connected, the router
will provide IP addresses for every computer that is connected to either device.

Configuration:
network icon in your task bar. If you are connecting your computers through a
switch with no router, you'll need to assign each computer on the network its own
individual IP address. This process is handled automatically if you're using a
router.[5]

Think of an IP address as a mailing address. Each computer on the network needs a


unique IP address so that information sent across the network reaches the correct
destination
Click Ethernet. It's near the top of the menu showing an ethernet cable next to a monitor.

Click next to "IP assignment." You may need to click "Ethernet" first to expand the menu.
Clicking this prompts a window to pop up
Select "Manual" from the drop-down menu.

Toggle IPv4 or IPv6, then edit the text fields. You can enable both or one of the toggles, then
continue with the next steps:

Enter
Enter
Enter
50 into the IP address field.
0 into the Subnet mask field.
0 into the Default gateway fi
Click Save. This will save the settings for that computer.

Open the "Network and Internet" settings on the next computer. Follow the steps
above on the second computer to open the same IP menu in "Ethernet".

Type 192 . 168 . 1 . 51 into the IP address field. Notice that the final group of numbers has
incremented by
Enter the same values for subnet and Gateway. These values should be the same as they were on
the first computer (255.255.0.0 and 192.168.0.0 respectively)

Give each additional computer a unique IP. Repeat these steps for each additional
computer, incrementing the IP address by 1 each time (up to 255). The "Subnet mask"
and "Gateway" fields should be the same on each computer.
LAN INSTALLATION OUTPUTS:

✅Successfully set up a wired and/or wireless LAN using routers, switches,


✅Connect multiple devices (PCs, laptops, printers, servers) to the LAN.
✅Verify connectivity between devices using ping and ipconfig/ifconfig.

LAN CONFIGURATION OUTPUT:

✅Access and configure the router's admin panel (192.168.1.50).


✅Set up IP addressing (static or dynamic via DHCP).
✅Secure the network by changing SSID, setting up WPA2/WPA3
encryption, and enabling firewalls.

RESULTS:

LAN installation and configuration involve hardware setup, IP management,


security settings, and troubleshooting. A properly configured LAN ensures
fast, secure, and reliable communication between devices.
Ex. No: 5
To implement various type of error correcting techniques.
Date:

AIM:

To implement various type of error correcting techniques

To implement various error-correcting techniques to ensure accurate data transmission over


unreliable networks. This practical demonstrates methods such as parity checks, checksums, and
cyclic redundancy checks (CRC) to detect and correct errors. By applying these techniques,
reliable communication can be achieved, minimizing the impact of transmission errors and
ensuring data integrity.

ALGORITHM:

1. Start
2. Input the binary data/message to be transmitted.
3. Display error correction options to the user:
o Parity Bit
o Hamming Code
o Checksum
o CRC
4. User selects one technique.
5. Encode the message using the selected method:
o Parity Bit: Add 1 parity bit based on even/odd parity.
o Hamming Code: Insert redundancy bits at power-of-two positions and calculate
their values.
o Checksum: Divide data into blocks, sum them, and append the checksum.
o CRC: Perform binary division using generator polynomial and append the
remainder (CRC bits).
6. Simulate transmission:
o Optionally introduce an error (flip 1 or more bits).
7. At receiver side:
o Decode the message using the same method.
o Check for errors.
o Correct the error (if applicable, e.g., in Hamming Code).
8. Display results:
o Original message
o Transmitted message
o Received message
o Error detected or corrected (Yes/No)
9. End
PROGRAM:

import java.util.Scanner;

public class ErrorCorrectionDemo {

// 1. Parity Bit (Even parity)

public static int calculateParity(String data) {

int count = 0;

for (char c : data.toCharArray()) {

if (c == '1') count++; }

return count % 2 == 0 ? 0 : 1; }

// 2. Checksum

public static int calculateChecksum(int[] data) {

int sum = 0;

for (int num : data) sum += num;

return ~(sum) + 1; // Two's complement of the sum }

// 3. Hamming Code (7,4)

public static String hammingEncode(String data) {

int d1 = data.charAt(0) - '0';

int d2 = data.charAt(1) - '0';

int d3 = data.charAt(2) - '0';

int d4 = data.charAt(3) - '0';


int p1 = d1 ^ d2 ^ d4;

int p2 = d1 ^ d3 ^ d4;

int p3 = d2 ^ d3 ^ d4;

return "" + p1 + p2 + d1 + p3 + d2 + d3 + d4;}

// 4. CRC (Cyclic Redundancy Check)

public static String computeCRC(String data, String divisor) {

int dataLen = data.length();

int divisorLen = divisor.length();

String dividend = data + "0".repeat(divisorLen - 1);

String remainder = divideCRC(dividend, divisor);

return remainder;}

public static String divideCRC(String dividend, String divisor) {

char[] result = dividend.toCharArray();

int divisorLen = divisor.length();

for (int i = 0; i <= dividend.length() - divisorLen; ) {

for (int j = 0; j < divisorLen; j++) {

result[i + j] = result[i + j] == divisor.charAt(j) ? '0' : '1';}

while (i < result.length && result[i] != '1') i++;}

return new String(result).substring(result.length - (divisorLen - 1)) }

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

// 1. Parity

System.out.print("Enter binary data for Parity: ");

String binaryData = sc.next();

int parity = calculateParity(binaryData);

System.out.println("Parity bit (Even parity): " + parity);

// 2. Checksum

System.out.print("\nEnter number of integers for Checksum: ");

int n = sc.nextInt();

int[] numbers = new int[n];

System.out.print("Enter the integers: ");

for (int i = 0; i < n; i++) numbers[i] = sc.nextInt();

int checksum = calculateChecksum(numbers);

System.out.println("Checksum: " + checksum);

// 3. Hamming Code

System.out.print("\nEnter 4-bit binary data for Hamming Code: ");

String hammingInput = sc.next();

String hammingCode = hammingEncode(hammingInput);

System.out.println("Hamming Encoded (7-bit): " + hammingCode);

// 4. CRC

System.out.print("\nEnter binary data for CRC: ");


String data = sc.next();

System.out.print("Enter divisor (generator): ");

String divisor = sc.next();

String crc = computeCRC(data, divisor);

System.out.println("CRC Checksum: " + crc);

sc.close();}

OUTPUT:

RESULT:

The program for implementing various error correcting techniques was successfully executed.
Techniques like Hamming Code were applied to detect and correct single-bit errors. The
simulation showed accurate encoding, transmission, error detection, and correction. It verified
the importance of error control in reliable data communication.
Ex. No: 6
To implement various types of DLL protocols.
Date:

AIM:

Implementation of Various Data Link Layer (DLL) Protocols in C++.

THEORY:

The Data Link Layer (DLL) is responsible for framing, error detection, and flow control in
networking. Some key protocols used in DLL include:

Stop-and-Wait Protocol – Simple flow control mechanism


Go-Back-N (GBN) Protocol – Sliding window protocol
Selective Repeat (SR) Protocol – Efficient retransmission method

PROGRAM:

1. Stop-and-wait protocol:
OUTPUT:

2. GO-BACK-N (GBN) PROTOCOL:


OUTPUT:

3. SELECTIVE REPEAT (SR) PROTOCOL


OUTPUT :

RESULT:

The program to implement various types of Data Link Layer (DLL) protocols such as Stop-and-
Wait, Go-Back-N, and Selective Repeat was successfully executed. It demonstrated reliable
frame transmission, acknowledgment handling, and retransmission of lost or corrupted frames.
The simulation confirmed proper flow control and error control mechanisms at the DLL level,
ensuring accurate and orderly data delivery between sender and receiver processes.
Ex. No: 7 Imagine two processes communicate across a network. One process running
in your local system is web browser and the other process running in the
remote system is the web server. Once a connection is established between
Date: the web browser and web server, the server’s current date and time has to be
displayed in
web browser. Write a suitable program for this scenario.

AIM:

Imagine two processes communicate across a network. One process running in your local system
is web browser and the other process running in the remote system is the web server. Once a
connection is established between the web browser and webserver, the server’s current date and
time has to be displayed in web browser. Write a suitable program for this scenario.

ALGORITHM:

Start a socket server on the remote system.


Wait for connection from the client (web browser).
Once connected, fetch the current date and time from the server.
Format it as an HTTP response.
Send the response to the client.
Client browser displays the server’s date and time.

PROGRAM:

SERVER CODE:
CLIENT CODE:

#Include <unistd.h>
#include <arpa/inet.h>

#define PORT 8080


#define SERVER_IP "127.0.0.1" //

Change this to the server's IP address

using namespace std;

// Convert IP address
if (inet_pton(AF_INET,

SERVER_IP,

&serv_addr.sin_addr) <= 0) { cerr

<< "Invalid address / Address not

supported!" << endl; return 1;

// Connect to server
if (connect(sock, (struct

sockaddr*)&serv_addr,

sizeof(serv_addr)) < 0) { cerr <<

"Connection failed!" << endl;

return 1;
}
OUTPUT:

RESULT:

The client-server program was successfully executed. A socket-based connection was established
between the web browser and the server. Upon connection, the server fetched its current date and
time and sent it as an HTTP response. The web browser displayed this information correctly.
This demonstrates a basic web communication model using sockets.
Ex. A network communication model is created by establishing connection
d No: 8
between a client and a server. The connection is also guaranteed by
transferring client’s IP address to the server and displays it in the server’s
Date: premises. Write a program for the above situation.

AIM:

A network communication model is created by establishing connection between a


client and a server. The connection is also guaranteed by transferring client’s IP
address to the server and displays it in the server’s premises. Write a program for the
above situation.

ALGORITHM:

Server Side Algorithm:

1. Start the server socket and listen on a specific port.


2. Wait for a client to connect (accept connection).
3. Retrieve the client's IP address from the socket.
4. Display the client’s IP address on the server console.
5. Close the connection.

Client Side Algorithm:

1. Create a socket to connect to the server using its IP address and port.
2. Establish the connection.
3. Optionally, send a message (not required for IP display).
4. Close the socket.

PROGRAM:

SERVER CODE:

import java.io.*;
import java.net.*;
public class Server {
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(5000); // Port number
System.out.println("Server started. Waiting for client...");
Socket clientSocket = serverSocket.accept(); // Accept connection
InetAddress clientAddress = clientSocket.getInetAddress(); // Get IP
d
System.out.println("Client connected from IP: " + clientAddress.getHostAddress
// Close connection
clientSocket.close();
serverSocket.close();

} catch (IOException e) {
e.printStackTrace();}}}

CLIENT SIDE:

import java.io.*;
import java.net.*;

public class Client {


public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 5000); // Connect to server
System.out.println("Connected to server.");

// Close connection
socket.close();

} catch (IOException e) {
e.printStackTrace();
}
}
}

OUTPUT:
d

RESULT:

The client-server network communication model was successfully implemented using socket
programming. The server was able to:
 Establish a connection with the client.
 Obtain the client’s IP address using socket functions.
 Display the client’s IP address on the server side (server console).

This verified that:


 The socket connection between client and server was successfully created.
 The server correctly identified and displayed the client's IP address, confirming that the
connection is valid and traceable.
 The communication model demonstrates a practical understanding of network identity
and connection handling.

The output was as expected, where the server displayed the connected client’s IP address.
Ex. No: 9 Consider two processes client and server communicates across a network.
The client sends a message to the server in the request and the server
responds with the same message. Write a Socket program for the above
d Date:
mentioned scenario.

AIM:

Consider two processes client and server communicates across a network. The client
sends a message to the server in the request and the server responds with the same
message. Write a Socket program for the above mentioned scenario.

ALGORITHM:

Server Side Algorithm:

1. Start a ServerSocket and bind it to a port.


2. Wait for a client to connect using accept().
3. Create input and output streams to receive and send messages.
4. Read the message from the client.
5. Send the same message back to the client.
6. Close the streams and sockets.

Client Side Algorithm:

1. Create a socket and connect to the server’s IP and port.


2. Create input/output streams to send/receive data.
3. Send a message to the server.
4. Read the server's response (which is an echo of the same message).
5. Display the echoed message.
6. Close the streams and socket.
PROGRAM:

SERVER SIDE:

import java.io.*;
import java.net.*;

public class Server {


public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(6000);
System.out.println("Server is running... Waiting for client.");

Socket clientSocket = serverSocket.accept(); // Wait for client


System.out.println("Client connected.");

// Streams
BufferedReader input = new BufferedReader
PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true);

// Read message from client


String message = input.readLine();
System.out.println("Received from client: " + message);

// Echo message back


output.println("Echo from server: " + message);

// Close connections
input.close();
output.close();
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();}}}
CLIENT SIDE:

import java.io.*;
import java.net.*;

public class Client {


public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 6000); // Connect to server
System.out.println("Connected to server.");

// Streams
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader input = new BufferedReader

// Send message
System.out.print("Enter message to send: ");
String message = userInput.readLine();
output.println(message);

// Read echo from server


String response = input.readLine();
System.out.println("Server response: " + response);

// Close connections
input.close();
output.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();}}}
OUTPUT:

RESULT:

The client-server socket program was successfully implemented and executed. The client sent a
message to the server over the network, and the server responded with the same message,
demonstrating a basic echo communication model.
This program verified that:

 Socket creation, connection establishment, and data transmission between client and
server were successful.
 Both client and server could send and receive messages reliably.
 It confirmed a foundational understanding of network communication using sockets,
which is essential for building more complex distributed systems and applications.

The output was as expected, where:


 The client's input message was echoed back from the server and displayed correctly.
Ex. No: 10
To study various TCL commands.
Date:

AIM:

To study and demonstrate the use of various TCL commands such as variable declaration,
conditional statements, loops, procedures, and file operations.

ALGORITHM:

1. Start the TCL interpreter or create a .tcl file.


2. Declare and initialize variables using the set command.
3. Use conditional statements (if, else) to check conditions.
4. Use looping structures like for, while, and foreach.
5. Create and call user-defined procedures using proc.
6. Perform file operations like reading and writing using open, puts, and gets.
7. Execute the script and observe the output for each command type.

PROGRAM:

# Variable Declaration and Initialization


set name "Taruna"
set age 21

# Display variables
puts "Name: $name"
puts "Age: $age"

# Conditional Statement
if {$age >= 18} {
puts "Status: Adult"
} else {
puts "Status: Minor"
}

# Loop - For
puts "\nFor loop from 1 to 5:"
for {set i 1} {$i <= 5} {incr i} {
puts "i = $i"
}

# Loop - While
puts "\nWhile loop till i < 3:"
set i 0
while {$i < 3} {
puts "i = $i"
incr i
}

# foreach loop
puts "\nForeach loop:"
foreach item {apple banana mango} {
puts "Fruit: $item"
}

# Procedure
proc greet {person} {
puts "Hello, $person! Welcome to TCL."
}
greet "Taruna"

# File Operations
set filename "sample.txt"

# Write to file
set file [open $filename "w"]
puts $file "This is a TCL file writing example."
close $file

# Read from file


set file [open $filename "r"]
set content [read $file]
close $file
puts "\nFile Content:"
puts $content

OUTPUT:
RESULT:

The TCL program was successfully executed and demonstrated various commands such as
variable declaration, conditional logic, looping structures, procedure definition, and file
handling. This helped in understanding the core functionality and syntax of TCL scripting.
Ex. No: 11 The message entered in the client is sent to the server and the server encodes
the message and returns it to the client.
Date: Encoding is done by replacing a character by the character next to
it.(i.e.) a as b, b as c…z as a.

AIM:

To implement a client-server communication model where the client sends a message to the
server, and the server encodes the message by replacing each character with the next character in
the alphabet, then returns the encoded message to the client.

ALGORITHM:

Server Side:

1. Start a server socket and wait for a client connection.


2. Accept the client's connection.
3. Read the message sent by the client.
4. Encode the message by shifting each alphabet character to its next one (wrap z→a,
Z→A).
5. Send the encoded message back to the client.
6. Close the connection.

Client Side:

1. Connect to the server using its IP and port.


2. Send a message to the server.
3. Receive the encoded message from the server.
4. Display the encoded message.
5. Close the connection.

PROGRAM:

SERVER CODE:

import java.io.*;
import java.net.*;

public class Server {


public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(7000);
System.out.println("Server started and waiting for client...");

Socket clientSocket = serverSocket.accept();


System.out.println("Client connected.");

BufferedReader input = new BufferedReader(new


InputStreamReader(clientSocket.getInputStream()));
PrintWriter output = new PrintWriter(clientSocket.getOutputStream(), true);

String message = input.readLine();


System.out.println("Received from client: " + message);

String encodedMessage = encodeMessage(message);


output.println(encodedMessage);
System.out.println("Sent encoded message: " + encodedMessage);

input.close();
output.close();
clientSocket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public static String encodeMessage(String message) {


StringBuilder encoded = new StringBuilder();
for (char c : message.toCharArray()) {
if (c >= 'a' && c <= 'z') {
encoded.append(c == 'z' ? 'a' : (char)(c + 1));
} else if (c >= 'A' && c <= 'Z') {
encoded.append(c == 'Z' ? 'A' : (char)(c + 1));
} else {
encoded.append(c); // leave other characters unchanged
}
}
return encoded.toString();
}
}

CLIENT CODE:

import java.io.*;
import java.net.*;
public class Client {
public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 7000);
System.out.println("Connected to server.");

BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));


PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader input = new BufferedReader(new
InputStreamReader(socket.getInputStream()));

System.out.print("Enter a message: ");


String message = userInput.readLine();

output.println(message);
String encoded = input.readLine();

System.out.println("Encoded message from server: " + encoded);

output.close();
input.close();
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

OUTPUT:

SERVER TERMINAL:

Server started and waiting for client...


Client connected.
Received from client: Hello Zebra!
Sent encoded message: Ifmmp Afcsb!

CLIENT TERMINAL:

Connected to server.
Enter a message: Hello Zebra!
Encoded message from server: Ifmmp Afcsb!
RESULT:

The client-server socket program was successfully implemented. The client sends a message to
the server, the server encodes it by shifting each alphabet character to the next, and the encoded
message is sent back and displayed by the client. The program demonstrated effective socket
communication and basic text encoding.
Ex. No: 12 Packet Tracer: Observing Packets across the network and Performance
Analysis of
Date: Routing protocols

AIM:

To simulate a network using Cisco Packet Tracer, observe packet flow across the network, and
analyze the performance of routing protocols (RIP, OSPF, EIGRP) using packet inspection tools
and simulation mode.

ALGORITHM:

Network Design
 Open Cisco Packet Tracer.
 Place required network devices (e.g., routers, switches, and PCs).
 Connect the devices using appropriate cables.
IP Addressing
 Assign IP addresses to all PCs and routers.
 Use different subnets for different networks.
Routing Protocol Configuration
 Configure static or dynamic routing on routers using:
o RIP using router rip
o OSPF using router ospf
o EIGRP using router eigrp
 Advertise the correct networks in each protocol.
Testing Connectivity
 Ping between PCs in different networks to verify successful routing.
Packet Inspection
 Switch to Simulation Mode in Packet Tracer.
 Add a PING packet and observe its journey.
 Watch how the routing protocol updates and data packets flow.
Performance Analysis
 Compare:
o Convergence time (how fast routes are learned)
o Number of updates exchanged
o Path taken by packets
 Use the event list to analyze packet routing behavior.
PROGRAM:
CONFIGURATION:

On Router1:

enable
configure terminal
interface fastEthernet 0/0
ip address 192.168.1.1 255.255.255.0
no shutdown

router ospf 1
network 192.168.1.0 0.0.0.255 area 0

On Router2:

enable
configure terminal
interface fastEthernet 0/0
ip address 192.168.2.1 255.255.255.0
no shutdown

router ospf 1
network 192.168.2.0 0.0.0.255 area 0

OUTPUT:

Ping packet initiated from PC0 to PC1.


Packet passes through the network as per OSPF routing tables.
Convergence observed in real-time.
In the event list:
 OSPF updates exchanged before data transmission.
 Routes established.
 ICMP Echo and Echo Reply packets visible.

PC0 sends ICMP Echo Request → Router1 → Router2 → PC1


PC1 sends ICMP Echo Reply → Router2 → Router1 → PC0
RESULT:

The network was successfully configured in Packet Tracer. Routing protocols (OSPF in this
case) were correctly implemented and tested. Packet traversal was observed using simulation
mode. Performance parameters like convergence time and routing behavior were analyzed using
event lists and packet flow visualization.

You might also like