COMPUTER-NETWORK-LAB-MANUAL
COMPUTER-NETWORK-LAB-MANUAL
EVEN SEMESTER
IEM
IT Department
Course Code : PCC-CS692
Course Title : Computer Networks Lab
Module 1 [6L]
1. Getting started with Basics of Network configurations files and Networking Commands in
Linux.
2. To familiarize and understand the use and functioning of System Calls used for Operating
system and network programming in Linux.
3. Familiarization and implementation of programs related to Process and thread. 4.
Implement the First Readers-Writers Problem.
Module 2 [6L]
4. Implement programs for Inter Process Communication using PIPE, Message Queue and
Shared Memory.
5. Implement Client-Server communication using Socket Programming and TCP and UDP as
transport layer PROTOCOL. *
6. Implement a multi user chat server using TCP as transport layer protocol. *
7. Implement Concurrent Time Server application using UDP to execute the program at
remote server. Client sends a time request to the server; server sends its system time back
to the client. Client displays the result. *
Module 3 [6L]
Implement and simulate algorithm for Distance vector routing protocol.
Implement and simulate algorithm for Link state routing protocol.
Using Wireshark observe data transferred in client server communication using UDP and
identify the UDP datagram.
Using Wireshark observe Three Way Handshaking Connection Establishment, Data Transfer and
Three-Way Handshaking Connection Termination in client server communication usingTCP.
Module 4 [6L]
Develop a packet capturing and filtering application using raw sockets.
Design and configure a network with multiple subnets with wired and wireless LANs using required
network devices. Configure the following services in the network- TELNET, SSH, FTPserver, Web
server, File server, DHCP server and DNS server.*
Install network simulator GNS3 in any of the Linux operating system and simulate wired and
wireless scenarios.
Text Books:
1. Data Communication and Networking, 4th Edition, Behrouz A. Forouzan, McGrawHill.
2. Data and Computer Communication, 8th Edition, William Stallings, Pearson
Prentice HallIndia.
3. Routing and Switching, Cisco Press
Reference Books:
1. Computer Networks, 8th Edition, Andrew S. Tanenbaum, Pearson New International
Edition.
2. Internetworking with TCP/IP, Volume 1, 6th Edition Douglas Comer, Prentice Hall of
India.
3. TCP/IP Illustrated, Volume 1, W. Richard Stevens, Addison-Wesley, United
States ofAmerica.
NETWORK LAB PREREQUISITE
AIM
To study the basic networking commands.
C:\>arp –a: ARP is short form of address resolution protocol, It will show the IP
address of your computer along with the IP address and MAC address of your
router.
C:\>hostname: This is the simplest of all TCP/IP commands. It simply displays the
name of your computer.
C:\>ipconfig: The ipconfig command displays information about the host (the
computer your sitting at) computer TCP/IP configuration.
C:\>ipconfig /all: This command displays detailed configuration information about your
TCP/IP connection including Router, Gateway, DNS, DHCP, and type of Ethernet adapter in
your system.
C:\>Ipconfig /renew: Using this command will renew all your IP addresses that you are
currently (leasing) borrowing from the DHCP server. This command is a quick problem
solver if you are having connection issues, but does not work if you have been configured
with a static IP address.
C:\>Ipconfig/release: This command allows you to drop the IP lease from the DHCP server.
C:\>ipconfig /flushdns: This command is only needed if you’re having trouble with your
networks DNS
configuration. The best time to use this command is after network configuration sets in, and you
really need the computer to reply with flushed.
C:\>nbtstat –a: This command helps solve problems with NetBIOS name
resolution. (Nbt stands for NetBIOS over TCP/IP)
C:\>net diag: Netdiag is a network testing utility that performs a variety of network
diagnostic tests, allowing you to pinpoint problems in your network. Netdiag isn’t installed
by default, but can be installed from the Windows XP CD after saying no to the install.
Navigate to the CD ROM drive letter and open the support\tools folder on the XP CD and
click the setup.exe icon in the support\tools folder.
C:\>nslookup: Nslookup is used for diagnosing DNS problems. If you can access a resource by
specifying an IP address but not it’s DNS you have a DNS problem.
C:\>pathping: Pathping is unique to Window’s, and is basically a combination of the Ping and
Tracert commands. Pathping traces the route to the destination address then launches a 25
second test of each router along the way, gathering statistics on the rate of data loss along
each hop.
C:\>ping: Ping is the most basic TCP/IP command, and it’s the same as placing a phone call
to your best friend. You pick up your telephone and dial a number, expecting your best
friend to reply with “Hello” on the other end. Computers make phone calls to each other
over a network by using a Ping command. The Ping commands main purpose is to place a
phone call to another computer on the network, and request an answer. Ping has 2 options
it can use to place a phone call to another computer on the network. It can use the
computers name or IP address.
C:\>route: The route command displays the computers routing table. A typical computer, with a
single network interface, connected to a LAN, with a router is fairly simple and generally
doesn’t pose any network problems. But if you’re having trouble accessing other computers
on your network, you can use the route command to make sure the entries in the routing table
are correct.
C:\>tracert: The tracert command displays a list of all the routers that a packet has to go
through to get from the computer where tracert is run to any other computer on the internet.
STUDY OF DIFFERENT TYPES OF CABLES
Transmission Medium:
A communication channel that is used to carry the data from one transmitter to the receiver
through the electromagnetic signals. The main function of this is to carry the data in the bits
form through the Local Area Network(LAN). In data communication, it works like a physical
path between the sender & receiver. For instance, in a copper cable network the bits in the
form of electrical signals whereas in a fiber network ,the bits are available in the form of light
pulses. The quality as well as characteristics of data transmission, can be determined from the
characteristics of medium &signal. The properties of different transmission media are delay,
bandwidth, maintenance, cost and easy installation.
Coaxial Cable:
Coaxial cable (or coax) carries signals of higher frequency ranges than those in twisted pair
cable. It has a central core conductor of solid or stranded wire (usually copper) enclosed in an
insulating sheath, which is, in turn, encased in an outer conductor of metal foil, braid, or a
combination of the two. The outer conductor is also enclosed in an insulating sheath, and the
whole cable is protected by a plastic cover.
Applications:
1. Coaxial cable was widely used for both analog and digital data transmissions.
2. It has higher bandwidth.
3.Inexpensive when compared to fiber optical cables.
4. It uses for longer distances at higher data rates.
5. Excellent noise immunity.
6. Used in LAN and Television distribution.
Disadvantage :
1.Single cable failure can fail the entire network.
2.Difficult to install and expensive when compared with twisted
pairs. 3.If the shield is imperfect, it can lead to grounded loop.
Unguided medium transport electromagnetic waves without using a physical conductor. This
type of communication is often referred to as wireless communication. Signals are normally
broadcast through free space and thus are available to anyone who has a device capable of
receiving them
Types of propagation:
1. Troposphere
2. Ionosphere
Microwaves:
It is a line of sight transmission i.e. the sending and receiving antennas need to be properly
aligned with each other. The distance covered by the signal is directly proportional to the
height of the antenna. Frequency Range:1GHz – 300GHz. These are majorly used for mobile
phone communication and television distribution.
Infrared:
Infrared waves are used for very short distance communication. They cannot penetrate
through obstacles. This prevents interference between systems. Frequency Range:300GHz –
400THz. It is used in TV remotes, wireless mouse, keyboard, printer, etc.
PRACTICALLY IMPLEMENT THE CROSS – WIRED CABLE AND
STRAIGHT WIRED CABLE USING CRIMPING TOOL
Aim: Study of different types of Network cables and Practically implement the
cross-wired cable and straight through cable using clamping tool.
tester. Procedure:
Crimping Tools:
A crimping tool is a device used to conjoin two pieces of metal by deforming one or both of
them to hold each other. The result of the tool's work is called a crimp. An example of
crimping is affixing a connector to the end of a cable. For instance, network cables and
phone cables are created using a crimping tool (shown below) to join RJ-45 and RJ-11
connectors to both ends of phone or Cat 5 cable.
UTP Cables:
UTP stands for Unshielded Twisted Pair cable. UTP cable is a 100 ohm copper cable that
consists of 2 to 1800 unshielded twisted pairs surrounded by an outer jacket. They have no
metallic shield. This makes the cable small in diameter but unprotected against electrical
interference. The twist helps to improve its immunity to electrical noise and EMI.
RJ-45 Connector:
RJ-45 connector is a tool that we put on the end of the UTP cable. With this we can plug
the cable in the LAN port.
Cable test:
A cable tester is a electronic device used to verify the electrical connections in a signal cable
or other wired assembly. Basic cable testers are continuity tester that verify the existence of a
conductive path between ends of the cable, and verify the correct wiring of connectors on the
cable
Straight cable:
A straight-through cable is a type of twisted pair cable that is used in local area networks to
connect a computer to a network hub such as a router. This type of cable is also sometimes
called a patch cable and is an alternative to wireless connections where one or more computers
access a router through a wireless signal. On a straight-through cable, the wired pins
match. Straightthrough cable use one wiring standard: both ends use T568A wiring
standard or both ends use T568B wiring standard. The following figure shows a straight-
through cable of which both ends are wired as the T568B standard.
Cross cable:
An Ethernet crossover cable is a type of Ethernet cable used to connect computing devices
together directly. Unlike straight-through cable, crossover cables use two different wiring
standards: one end uses the T568A wiring standard, and the other end uses the T568B wiring
standard. The internal wiring of Ethernet crossover cables reverses the transmit and receive
signals. It is most often used to connect two devices of the same type: e.g. two computers (via
network interface controller) or two switches to each other.
Orange White on no
1 Orange on no 2
Green White on no
3 Blue on no 4
Blue White on no 5
Green on no 6
White Brown on no 7
Brown on no 8
- Make crimping using crimp tools , press crimping tool and make sure all the pins ( brass ) on
the RJ - 45 connector has " bite " of each cable . usually when done will sound "click ".
Once finished at the end of this one , do it again at the other end cable. The final step is to
check the cable that you created earlier using the LAN tester , enter each end of the cable (
RJ- 45 ) to each LAN port available on the tester , turn and make sure all of the LEDs light
up according to the order of the wires we created.
For the second end of the cable, the colour composition is different from the first . The
colour arrangement is as follows
The IP address stands for Internet Protocol address is also called IP number or internet
address. It helps us to specify the technical format of the addressing and packets scheme.
An IP address is a numerical label assigned to the devices connected to a computer
network that uses the IP for communication. IP address act as an identifier for a specific
machine on a particular network. It also helps us to develop a virtual connection between
a source and a destination.
Types of IP address
There are mainly four types of IP addresses:
• Public
• Private
• Static
• Dynamic.
Public IP Addresses
A public IP address is an address where one primary address is associated with the
whole network. In this type of IP address, each of the connected devices has the same
IP address. This type of public IP address is provided by Internet Service Provider
(ISP).
Private IP Addresses
A private IP address is a unique IP number assigned to every device that connects to
internet network, which includes devices like computers, tablets, smartphones etc.,
Static IP addresses
A static IP address is an IP address that cannot be changed. These are fixed that are
manually assigned to a system device. On the network configuration page, the network
administrator manually inputs the IP address for every system. Moreover, the static
address is not changed until it is directly updated by the network administrator or the
Internet Service Provider. Furthermore, this address does not change with each network
connection. In other words, the device always connects to the internet through the same
IP address.
Dynamic IP addresses
The dynamic IP address is typically configured on devices via the DHCP protocol and
regularly updates. The dynamic IP address constantly changes whenever the user links to a
network. The Dynamic Host Configuration Protocol(DHCP) server employs a method
for tracking and retrieving IP address information associated with active network
components. The mechanism utilized for translation in dynamic address is known as
Domain Name Server (DNS).
The DHCP and DNS are two protocols that are widely used while accessing the internet.
When a user connects to the network, DHCP assigns a temporary dynamic IP address.
The main differences between Static and Dynamic IP addresses are as follows:
Features Static IP address Dynamic IP address
Device tracking Devices may be traced easily. Devices may be difficult to trace.
The Internet Protocol version 4 (IPv4) is a protocol for use on packet-switched Link
Layer networks (e.g. Ethernet). IPv4 provides an addressing capability of approximately
4.3 billion addresses. The Internet Protocol version 6 (IPv6) is more advanced and has
better features compared to IPv4.
Classes IPv4 has 5 different classes of IPv6 does not contain classes of IP
IP address that includes Class addresses.
A, Class B, Class C, Class D,
and Class E.
Number of IP address IPv4 has a limited number of IP IPv6 has a large number of IP addresses.
addresses.
Address configuration It supports manual and DHCP It supports manual, DHCP, auto-
configuration. configuration, and renumbering.
Security features In IPv4, security depends on In IPv6, IPSEC is developed for security
the application. This IP address purposes.
is not developed in keeping the
security feature in mind.
Address representation In IPv4, the IP address is In IPv6, the representation of the IP
represented in decimal. address in hexadecimal.
Packet flow identification It does not provide any It uses flow label field in the header for
mechanism for packet flow the packet flow identification.
identification.
Checksum field The checksum field is available The checksum field is not available in
in IPv4. IPv6.
The Subnetting basically convert the host bits into the network bits. As mentioned above the
subnetting strategy was initially devised for slowing down the depletion of the IP
addresses.
The subnetting permits the administrator to partition a single class A, class B, class C
network into smaller parts. VLSM (Variable Length Subnet Mask) is a technique which
partitions IP address space into subnets of different sizes and prevent memory wastage.
Furthermore, when the number of hosts is same in subnets, that is known as FLSM (Fixed
Length Subnet Mask).
Supernetting is inverse process of subnetting, in which several networks are
merged into a single network. While performing supernetting, the mask bits are
moved toward the left of the default mask. The supernetting is also known as
router summarization and aggregation. It results in the creation of more host
addresses at the expense of network addresses, where basically the network bits are
converted into host bits.
The supernetting is performed by internet service provider rather than the normal
users, to achieve the most efficient IP address allocation. CIDR (Classless Inter-
Domain Routing) is scheme used to route the network traffic across the internet.
CIDR is a supernetting technique where the several subnets are combined together
for the network routing. In simpler words, CIDR allows the IP addresses to be
organized in the subnetworks independent of the value of the addresses.
IPV4
IPV6
STUDY OF NETWORK DEVICES ( SWITCH, ROUTER BRIDGE)
• Switch
• Bridge
• Router
practical.
Working of Switch:-Whenever a host sends a frame to any other host, then the source host
is stored with the port in the address table of the MAC address switch. A switch always
stores the address of the source in the table. Unless a host does send some data, its MAC
address and port number will not be stored in the table of the switch. When you initialize
the switch, the switch does not contain any information about any host and its address.
In such a situation, when a host frame sends, its MAC address is stored in the table but
due to no destination information, the switch sends the frame to all the hosts. When you
initialize the switch, the switch does not contain any information about any host and its
address. As soon as the second host sends some data, its address also gets stored in the
table. Whenever a host sends the frames, the switch stores it if its address is not already
present in the table. Thus a switch creates its table. When all the hosts' addresses and port
numbers come in the switch, the switch delivers the frame to all hosts only, delivering the
same host to the host for which the data has been sent.
2. Bridge: A network bridge connects multiple network segments at the data link layer
(Layer 2) of the OSI model. In Ethernet networks, the term bridge formally means a
device that behaves according to the IEEE 802.1D standard. A bridge and switch are
very much alike; a switch being a bridge with numerous ports. Switch or Layer 2
switch is often used interchangeably with bridge. Bridges can analyze incoming data
packets to determine if the bridge is able to send the given packet to another segment
of the network.
Bridge:-
Bridge is termed as a network device which is helpful in filtering the data load of the traffic
by dividing it into segments or packets. They are used to lower the load of traffic on the
LAN and other networks. Bridges are passive devices, because there is no interaction
between bridged and the paths of bridging. Bridges operate on the second layer of the
OSI model that is the data link layer.
Working of Bridge:-
When various network segments are established at the data link layer of the OSI model, we
refer to it as bridge. However when the packets of data are transferred along a network ,
without locating the network addresses this process is termed as bridging. The process of
bridging is helpful in locating the addresses of unknown addresses to which it is viable to
send data. In bridging the data packets contain a header or a packet header which holds
the address to the intended device. Bridge can remember and recall the address of the
devices for further transmission. There are two kinds of bridging modes, the transparent
bridging and the source routing bridging. When the process of bridging occurs, it
makes a bridging table along side where it stores the MAC addresses of the various
terminals. This table helps the bridges to send the data packet to the exact location
next time. However when a specific address does not meet the contents of the bridging
table, the data packet is forwarded further ahead to every attached terminal in LAN except
from the computer it is connected to. This type of bridging is called transparent
bridging. When the source computer presents pathway information within the packet,
this type of bridging is known as source route bridging. It is most commonly used in used
on Token Ring networks.
3. Router: A router is an electronic device that interconnects two or more computer
networks, and selectively interchanges packets of data between them. Each data packet
contains address information that a router can use to determine if the source and
destination are on the same network, or if the data packet must be transferred from one
network to another. Where multiple routers are used in a large collection of
interconnected networks, the routers exchange information about target system addresses,
so that each router can build up a table showing the preferred paths between any two
systems on the interconnected networks.
Router:-
Select port status check box on . (for which Ethernet switch connected)
Step -3 Configure Server IP address 192.168.1.101 and connect to switch by Straight
Through cable.
Step -4 Connect all 05 PCs to switch using Straight Through cable and configure IP address
as 192.168.1.1 to 192.168.1.5
Step -6 Configure Printer IP 192.168.1.102 and connect to switch using Straight Through
cable.
Click on Printer
Click in any one PC, Click on Desktop, Click on Command Prompt and ping any pc from
this
PC
Step 3: Right-click on “Outbound Rules” from the menu on the left and select “New Rule.”
Step 4: When a new window pops up, select the “Custom” option followed by “Next.”
Step 5: On the next window, select “All programs” and again select “Next.”
Step 6: Select the ” These IP addresses ” option under “Which remote IP addresses does
this rule apply to?” and click next
Step 7: Open the Command Prompt as Administrator by entering “CMD” into the search
box.
Step 10 : Make sure to choose the “Block the connection” option and click on “Next.”
Step 11: Choose whether the rule applies to Domain, Private, or Public. You can also
select all three.
Step 12 : Select “Next,” add a name or description for this rule, and select “Finish” to
complete the action.
Type text ( Share the file in a system and access the files from other system or
server using IP address)
command prompt
Check the file by entering
C: \> dir
C:\> ftp 192.168.1.1 ( Enter the IP address of Server to connect Server )
Give Username and Password
ftp> put test1.txt (File transferred from PC1 to Server)
ftp> dir (Check the file is transferred to server by giving dir
command) test1.txt
Double click on printer, Click on Config, Select FastEthernet0, Give IPV4 address. And
connect to switch using Straight Through cable.
Step -3 Connect all 02 PCs to switch using Straight Through cable and configure IP address as
192.168.1.1 and192.168.1.2
Click in any one PC, Click on Desktop, Click on Command Prompt and ping printer from
02 - PCs, 01- Printer, 01- Laptop, 01- server, 01- smart phone and 01- HomeRouter
By using Drag and Drop
Click on desktop
Click on DHCP
Next click on config
Click on wireless0
Click on WPA-PSK and give PSK PASS Phrase (12345678)
Change SSID default to IEM
PC will get connect to router
Step -5 Repeat Step 3rd to make Laptop, Printer, Server and Smartphone wireless
Click in any device, Click on Desktop, Click on Command Prompt and ping any pc from
printer
OR
Step -7 Switch(config)#Exit
To check for configuration password ( i.e Login to Switch) First need to enter console
password
User Access Verification
Switch> En /Enable
Switch#
Using cutting tool cut 1 inch off the jacket from the top of the cable. If using scissors or
another cutting device make sure not to cut through the wires in the cable.
If cable also has a spline / cross separator in the cable, then cut off the portion that is showing.
Try to cut off the without damaging the wires.
1. Orange stripe
2. Orange
3. Green Stripe
4. Blue
5. Blue stripe
6. Green
7. Brown stripe
8. Brown
Try not to insert the cables jacket too far in to the keystone jack. Try to get the jack just
inside or touching the end of the jack. The other important thing to mention here is to
not have any wiring exposed from the jack to the jack.
Using the wiring scheme have chosen, lay down the wires in the grooves of the keystone jack.
Step -6 Put keystone jack in the 90° punch down tool
Using a punch down tool can now insert the jack in to the punch down area of the tool. Make
sure the degree of the punch down tool matches the degree of the keystone jack. Insert with
open side facing the grooves of the punch down tool.
By squeezing down on the punch down tool wires now firmly inside the contact area of the
jack. The wires hanging off the side should also have been cut off. If some weren't cut off
that is ok. Simply cut off the remaining portion using a cutting device.
For this step make sure to double check the wires are deep enough in the contact area. If
any of the wires are not in the contact area yet try using the tool again to punch them down.
tester. Procedure:
Check both cable end should be either T568A or both ends should be
code Step -6 Crimp cable using Crimping Tool for both the ends
SW2#Config t
SW2(Config)# int range fa 0/3-4 SW2(Config-
if)#switchport access vlan 3
PC9- (ARTS) to PC4 (CSC) – (VLAN 3 to VLAN 2 ) Will not send packets PC8-
(CSC) to PC5 (CSC) – (VLAN 3 to VLAN 3 ) Will send packets
LAB 3
CONFIGURE OF VPN USING PACKET TRACER / GNS3
Step - 1 : 02 PC’s, 03 Roouters
Step - 2 : Connect 01 PC to Router1 and other to Router 3 Step - 3 :
Configure IP for all PCS
PC 1- 192.168.1.2 Gateway IP 192.168.1.1
PC2 – 192.168.2.2 Gateway IP 192.168.2.1
Step -7 Router 0
Click on Config - > Click on Static - > Add Network -
0.0.0.0
Mask - 0.0.0.0
Next Hop - 1.0.0.1
Step -8 Router 2
Click on Config - > Click on Static - > Add Network -
0.0.0.0
Mask - 0.0.0.0
Next Hop - 2.0.0.1
Step – 13
Ping from PC1 – ping 192.168.2.2 Tracert
192.168.2.2
LAB 4
Implement shortest path (Dijkstra’s) algorithm in C/Java.
Dijkstra's algorithm
Dijkstra's algorithm - is a solution to the single-source shortest path problem in graph
theory.
Works on both directed and undirected graphs. However, all edges must have nonnegative
weights.
Input: Weighted graph G={E,V} and source vertex v∈V, such that all edge weights are
nonnegative
Output: Lengths of shortest paths (or the shortest paths themselves) from a given source
vertex v∈V to all other vertices
• Approach : The algorithm computes for each vertex u the distance to u from the start
vertex v, that is, the weight of a shortest path between v and u.
• the algorithm keeps track of the set of vertices for which the distance has been
computed, called the cloud C
• Every vertex has a label D associated with it. For any vertex u, D[u] stores an
approximation of the distance between v and u. The algorithm will update a D[u]
value when it finds a shorter path from v to u.
• When a vertex u is added to the cloud, its label D[u] is equal to the actual (final)
distance between the starting vertex v and vertex u.
Distance(source) = 0
0
0 ∞
2
A B
4 1 3 10
∞ C
2
D
2
E ∞
5 8 ∞ 4 6
1
F G
∞ ∞
0 2
2
A B
4 1 3 10
∞ C
2
D
2
E ∞
5 8 1 4 6
Distance(B) = 2 1
F G
Distance(D) = 1
∞ ∞
Example: Remove vertex with minimum distance
0 2
2
A B
4 1 3 10
∞ C
2
D
2
E ∞
5 8 1 4 6
1
F G
∞ ∞
4 1 3 10
2 2
3 C D E 3
5 8 1 4 6
Distance(C) = 1 + 2 = 3 1
F G
Distance(E) = 1 + 2 = 3
Distance(F) = 1 + 8 = 9 9 5
Distance(G) = 1 + 4 = 5
Example: Continued...
Pick vertex in List with minimum distance (B) and update neighbors
2
A B
4 1 3 10
2 2
3 C D E 3
5 8 1 4 6
1
F G
9 5
Note : distance(D) not updated since D is already known and distance(E) not updated since it
is larger than previously computed
LAB 5
Write a program to find the name and addresses of the local machine as well as a remote host
(also a group of remote hosts) using InetAddress class in Java.
LAB 6
One-way and two-way communication between client and server using socket programming in
Java.
import java.io*;
import java.net.*;
Class TCPClient {
public static void main (String argv[]) throws Exception {
String sentence;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader(
new InputStreamReader(system.in));
Socket clientSocket = new Socket(”hostname”, 6789);
DataOutpuStream outToServer = new DataOutputStream(
clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + ’\n’);
modifiedSentence = inFromServer.readLine();
System.out.println(”FROM SERVER: ” + modifiedSentence);
clientSocket.close(); } }
TCP SERVER
import java.io*;
import java.net.*;
Class TCPServer {
public static void main (String argv[]) throws Exception {
String clientSentence;
String capitalizedSentence;
ServerSocket welcomeSocket = new ServerSocket (6789);
while (true) {
Socket connenctionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader( new
InputStreamReader( connectionSocket.getInputStream()));
DataOutpuStream outToClient = new DataOutputStream(
connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + ’\n’;
outToClient.writeBytes(capitalizedSentence);
}}}
Socket Programming with UDP
• Connectionless
• No reliable datatransfer
UDP-client in Java
import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[ ]) throws Exception {
BufferedReader inFromUser = new BufferedReader(new
InputStreamReader(System.in)); DatagramSocket clientSocket =
new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName(”hostname”);
byte[ ] sendData = new byte[1024];
byte[ ] recieveData = new byte[1024];
String sentence = inFromUser.readLine();
sendData = sentence.getBytes ();
DatagramPacket sendPacket = new DatagramPacket(sendData,
sendData.length, IPAddress, 9876); clientSocket.send(sendPacket);
DatagramPacket receivePacket = new
DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
String modefiedSentence = new String(receivePacket.getData());
System.out.println(”FROM SERVER:” + modifiedSentence);
clientSocket.close();
}}
UDP-server in Java
import java.io.*;
import java.net.*;
class UDPClient {
public static void main(String args[ ]) throws Exception {
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[ ] receiveData = new byte[1024];
byte[ ] sendData = new byte[1024];
while(true) {
DatagramPacket receivePacket = new
DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);
String sentence = new String(receivePacket.getData());
InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String catitalizedSentence = sentence.toUpperCase();
sendData = capetalizedSentence.getBytes ();
DatagramPacket sendPacket = new DatagramPacket(sendData,
sendData.length, IPAddress, port); clientSocket.send(sendPacket);
DatagramPacket receivePacket = new
DatagramPacket(receiveData, receiveData.length);
serverSocket.send(sendPacket); } } }
LAB 7
LAB 8
Write a program to find whether a remote host is reachable or not using InetAddress class in
Java.
LAB 9
Implementing RIP and OSPF Routing Protocol in Packet Tracer Simulator.