0% found this document useful (0 votes)
53 views

Network Programming Lab Manual - Exp 1-5

Uploaded by

gowthammass633
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Network Programming Lab Manual - Exp 1-5

Uploaded by

gowthammass633
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Ex No.

: 1 Demo session of all networking hardware and Functionalities

Aim:- Study of all networking hardware and Functionalities

Define Network
A network consists of two or more computers that are linked in order to share resources (such as
printers and CDs), exchange files, or allow electronic communications. The computers on a
network may be linked through cables, telephone lines, radio waves, satellites, or infrared light
beams.

Networking Components:-
Computer networks components comprise both Hardware parts as well as the software parts
required for installing computer networks, both at organizations and at home. The hardware
components are the server, client, peer, transmission medium, and connecting devices. The
software components are operating system and protocols.

Components of Network.

Hardware Components:-
Servers: Servers are high-configuration computers that manage the resources of the network.
The network operating system is typically installed in the server and so they give user accesses to
the network resources. Servers can be of various kinds: file servers, database servers, print
servers etc.
Clients: − Clients are computers that request and receive service from the servers to access and
use the network resources.
Peers:- Peers are computers that provide as well as receive services from other peers in a
work group network.
Transmission Media:- Transmission media are the channels through which data is
transferred from one device to another in a network. Transmission media may be guided media
like coaxial cable, fiber optic cables etc; or maybe unguided media like microwaves, infra-red
wave etc.
Networking Devices:- Connecting devices act as middleware between networks or
computers, by binding the network media together. Some of the common connecting devices
are:
1. Routers
2. Hub
3. Switch
4. Bridge
5. Repeater
6. Gateway
Software Components:-

 Operating System − Network Operating Systems is typically installed in


the server and facilitate workstations in a n e t w o r k to share files,
database, applications, printers etc.
 Protocol Suite − A protocol is a rule or guideline followed by each computer
for data communication. Protocol suite is a set of related protocols that are
laid down for computer networks. The two popular protocol suites are−
 OSI Model ( Open System Interconnections)
 TCP / IP Model.

LAN Adapter:-
A LAN adapter is an expansion board that is used to connect a computer or computing
device to a network. LAN adapter is the most common and generic alternate name for a
Network Interface Card(NIC). Similar products, such as Wireless USB LAN Adapter rare
referred to as LAN adapters.

LAN ADAPTER
 Functions of LAN Adapter:-
The computer and the card must communicate with each other so that they can proceed to
exchange information. In this way, the computer allocates part of its memory to cards
that have DMA (Direct memory access).The card interface indicates that another computer is
requesting data from the computer. The computer bus transfers the data from the computer
memory to the network card.
Networking Devices

Router:
Routers are

OSI model. They are responsible for receiving, analyzing, and forwarding data packets among the
connected computer networks. When a data packet arrives, the router inspects the destination
address, consults its routing tables to decide the optimal route and then transfers the packet along
this route.

How a router works:-

A router examines a packet header's destination IP address and compares it against a routing
table to determine the packet's best next hop. Routing tables list directions for forwarding data to
particular network destinations, sometimes in the context of other variables, like cost. They
amount to an algorithmic set of rules that calculate the best way to transmit traffic toward any
given IP address. A routing table often specifies a default route, which the router uses whenever it
fails to find a better forwarding option for a given packet. For example, the typical home
office router directs all outbound traffic along a single default route to its internet service
provider (ISP) Routing tables can be static -- i.e., manually configured -- or dynamic. Dynamic
routers automatically updated their routing tables based on network activity, exchanging
information with other devices via routing protocols.

Hub:-
A Network Hub is one of the most commonly used networking devices can be easily
found on any small networks such as home or
office. Hub operates at the physical layer of OSI
model. It is the simplest networking device hence
has low cost. Basically, a hub is a repeater with
multiple ports. The function of a hub in
networking is similar to the repeater. It transfers
data in the form of binary bits and uses for
broadcasting data.

Working of Hubs:-When a host sends frames, the hub forwards the frames in all the ports. Hubs
do not separate the type of the frame, for example, whether the frame unicast should be either
multicast or broadcast. Hubs forward all the frames into all the ports. Although a hub s e n d s
the frames to all the ports, a computer accepts the ones, whose MAC match matches the
d e s t i n a t i o n MAC address field. The rest of the frames are discarded after receiving the
required information.
Switch:-

A switch is a Networking 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.

Diagram- Switch

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. 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. 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. As soon as the second host sends some data, its address also gets stored in the table. 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.
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.

Diagram: Working of Switch

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 ofdata 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.

Repeater:-

A repeater is a network device that retransmits a received signal with more power and to an
extended geographical or topological network boundary than what would be capable with the
original signal repeater is implemented in computer networks to expand the coverage area of the
network, re propagate a weak or broken signal and or service remote nodes. Repeaters amplify
the received/input signal to a higher frequency domain so that it is reusable, scalable.
Diagram: Repeater

Working of Repeater:-

When an electrical signal is transmitted via a channel, it gets attenuated depending upon the
nature of the channel or the technology. This poses a limitation upon the length of the LAN or
coverage area of cellular networks. This problem is alleviated by installing repeaters at certain
intervals.

Repeaters amplifies the attenuated signal and then retransmits it. Digital repeaters can even
reconstruct signals distorted by transmission loss. So, repeaters are popularly incorporated to
connect between two LANs thus forming a large single LAN

Gateway:-

The link between two computers to connect to internet or another


network is called gateway. The gateway works like a portal among two programs by means of
communications between protocol and permit them to share data on same computers or among
different computers. Gateways are also known as protocol converter that can perform at any
OSI model layer. The task of a gateway is very complex.
Working of Gateway:-
A gateway is a network point that works as an access to another network. Generally in
intranet a node can be either a gateway node or the nodes that join the network are gateways.
In large organization where the computers control the traffic between organization networks
are gateway nodes. Like that the computers used by ISP to connect different user with each
other at a time to the internet are gateway nodes. In a project of any business company
computer server work as a gateway nodes and it may be proxy server or firewall some
time.
A gateway may connected to a router
because a router exactly known where to
through a given packet of data that
appears at the gateway then a switch
finalize the actual in and out path of the
gateway for the specified packet .A gateway
is a compulsory features of routes even
though other devices can perform as a
gateway. The operating system mostly used
this term and internet connection sharing
act as a gateway and creating a connection
among internal network.

Working of Gateways
Ex.No. : 2 Use of Wireshark network tool

Aim:- Study and Use of Wireshark network tool

Download and install the Wireshark software: Go to http://www.wireshark.org/download.html


and download and install the Wireshark binary for your computer.

Running Wireshark When you run the Wireshark program, the Wireshark graphical user
interface shown in Figure below will be displayed. Initially, no data will be displayed in the
various windows.

Wireshark Graphical User Interface

The Wireshark interface has five major components:

 The command menus are standard pulldown menus located at the top of the window. Of
interest to us now are the File and Capture menus. The File menu allows you to save
captured packet data or open a file containing previously captured packet data, and exit
the Wireshark application. The Capture menu allows you to begin packet capture.
 The packet-listing window displays a one-line summary for each packet captured,
including the packet number (assigned by Wireshark; this is not a packet number
contained in any protocol’s header), the time at which the packet was captured, the
packet’s source and destination addresses, the protocol type, and protocol-specific
information contained in the packet. The packet listing can be sorted according to any of
these categories by clicking on a column name. The protocol type field lists the highest
level protocol that sent or received this packet, i.e., the protocol that is the source or
ultimate sink for this packet.

 The packet-header details window provides details about the packet selected 
(highlighted) in the packet listing window. (To select a packet in the packet listing
window, place the cursor over the packet’s one-line summary in the packet listing
window and click with the left mouse button.). These details include information about
the Ethernet frame (assuming the packet was sent/receiverd over an Ethernet interface)
and IP datagram that contains this packet. The amount of Ethernet and IP-layer detail
displayed can be expanded or minimized by clicking on the plus minus boxes to the left
of the Ethernet frame or IP datagram line in the packet details window. If the packet has
been carried over TCP or UDP, TCP or UDP details will also be displayed, which can
similarly be expanded or minimized. Finally, details about the highest level protocol that
sent or received this packet are also provided.

 The packet-contents window displays the entire contents of the captured frame, in both
ASCII and hexadecimal format.

 Towards the top of the Wireshark graphical user interface, is the packet display filter
field, into which a protocol name or other information can be entered in order to filter the
information displayed in the packet-listing window (and hence the packet-header and
packet-contents windows). In the example below, we’ll use the packet-display filter field
to have Wireshark hide (not display) packets except those that correspond to HTTP
messages.

 Taking Wireshark for a Test Run The best way to learn about any new piece of software
is to try it out! We’ll assume that your computer is connected to the Internet via a wired
Ethernet interface. Do the following

1. Start up your favorite web browser, which will display your selected homepage.

2. Start up the Wireshark software. You will initially see a window similar to that shown
in above Figure, except that no packet data will be displayed in the packetlisting, packet-
header, or packet-contents window, since Wireshark has not yet begun capturing packets.
3. To begin packet capture, select the Capture pull down menu and select Options. This
will cause the “Wireshark: Capture Options” window to be displayed, as shown in Figure
below.

4
.

Y
o
u

c
a
n

u
s
e

m
o
s
t

o
f

t
Wireshark Capture Options Window

The default values in this window, but uncheck “Hide capture info dialog” under Display
Options. The network interfaces (i.e., the physical connections) that your computer has to
the network will be shown in the Interface pull down menu at the top of the Capture
Options window. In case your computer has more than one active network interface (e.g.,
if you have both a wireless and a wired Ethernet connection), you will need to select an
interface that is being used to send and receive packets (mostly likely the wired
interface). After selecting the network interface (or using the default interface chosen by
Wireshark), click Start. Packet capture will now begin - all packets being sent/received
from/by your computer are now being captured by Wireshark!

5. Once you begin packet capture, a packet capture summary window will appear, as
shown in Figure 4. This window summarizes the number of packets of various types that
are being captured, and (importantly!) contains the Stop button that will allow you to stop
packet capture. Don’t stop packet capture yet.

Wireshark Packet Capture Window

6. While Wireshark is running, enter the URL: http://gaia.cs.umass.edu/wireshark-


labs/INTRO-wireshark-file1.html and have that page displayed in your browser. In order
to display this page, your browser will contact the HTTP server at gaia.cs.umass.edu and
exchange HTTP messages with the server in order to download this page, as discussed in
section 2.2 of the text. The Ethernet frames containing these HTTP messages will be
captured by Wireshark.

7. After your browser has displayed the INTRO-wireshark-file1.html page, stop


Wireshark packet capture by selecting stop in the Wireshark capture window. This will
cause the Wireshark capture window to disappear and the main Wireshark window to
display all packets captured since you began packet capture. You now have live packet
data that contains all protocol messages exchanged between your computer and other
network entities! The HTTP message exchanges with the gaia.cs.umass.edu web server
should appear somewhere in the listing of packets captured. But there will be many other
types of packets displayed as. Even though the only action you took was to download a
web page, there were evidently many other protocols running on your computer that are
unseen by the user. We’ll learn much more about these protocols as we progress through
the text! For now, you should just be aware that there is often much more going on than
“meet’s the eye”! 8. Type in “http” (without the quotes, and in lower case – all protocol
names are in lower case in Wireshark) into the display filter specification window at the
top of the main Wireshark window. Then select Apply (to the right of where you entered
“http”). This will cause only HTTP message to be displayed in the packet-listing window.

9. Select the first http message shown in the packet-listing window. This should be the
HTTP GET message that was sent from your computer to the gaia.cs.umass.edu HTTP
server. When you select the HTTP GET message, the Ethernet frame, IP datagram, TCP
segment, and HTTP message header information will be displayed in the packet-header
window3 . By clicking on right pointing and down-pointing arrow sheads to the left side
of the packet details window, minimize the amount of Frame, Ethernet, Internet Protocol,
and Transmission Control Protocol information displayed. Maximize the amount
information displayed about the HTTP protocol. Your Wireshark display should now
look roughly as shown in Figure below. (Note, in particular, the minimized amount of
protocol information for all protocols except HTTP, and the maximized amount of
protocol information for HTTP in the packet-header window).

10. Exit Wireshark


Wireshark display after step 9
Ex No 3: Use of Packet tracer network tool

Aim: To analyse the performance of various configurations and protocols in LAN

Requirements

 Windows pc – 3Nos
 CISCO Packet Tracer Software ( Student Version)
 8 port switch – 1 No
 Cat-5 LAN cable

Procedure

 Open the CISCO Packet tracer software


 Drag and drop 3 pcs using End Device Icons on the left corner
 Select 8 port switch from switch icon list in the left bottom corner
 Make the connections using Straight through Ethernet cables
 Give IP address of the PC1, PC2 and PC3 as 192.168.1.1, 192.168.1.2 and 192.168.1.3
respectively, ping between PCs and observe the transfer of data packets in real and
simulation mode.

Theory

A local area network (LAN) is a collection of devices connected together in one physical
location, such as a building, office, or home. A LAN can be small or large, ranging from a home
network with one user to an enterprise network with thousands of users and devices in an office
or school. A LAN comprises cables, access points, switches, routers, and other components that
enable devices to connect to internal servers, web servers, and other LANs via wide area
networks. The advantages of a LAN are the same as those for any group of devices networked
together. The devices can use a single Internet connection, share files with one another, print to
shared printers, and be accessed and even controlled by one another.

Network Topology Diagram for LAN


Ex No 4: Implementation of Error Detection and Error Correction Techniques.

Aim : To Implementation of Error Detection and Error Correction Techniques.

Algorithm:

1. In the first step, we append N 0's to the data unit. The value of N is always less than the
number of bits in the data unit(referred to as division which is N+1).

2. In the next step, we use the process of binary division for dividing the newly extended
data by a divisor, and the reminder which we get from this division is referred to as CRC
remainder.

3. In the next step, we replace all the 0's which we append before in the data unit with the
remainder bits. After that, we sent the newly generated data unit to the receiver.

4. The receiver receives the data unit with the CRC remainder. After that, the receiver
divides the data unit by the divisor.

5. If the remainder is zero after dividing the data unit with the divisor, unit data is not
corrupted and can be accepted.

6. If the remainder is not equal to zero after dividing the data unit with the divisor, unit data
is corrupted and will be discarded.

Program:

// import required classes and packages


package javaTpoint.MicrosoftJava;
import java.util.*;
// create CRCExample class to demonstrate the working of Cyclic Redundancy Check
class CRCExample {
// main() method start
public static void main(String args[]) {
// create scanner class object to take input from user
Scanner scan = new Scanner(System.in);
// declare n for the size of the data
int size;
// take the size of the data from the user
System.out.println("Enter the size of the data array: ");
size = scan.nextInt();
// declaration of the data array
int data[] = new int[size];
// take bits of the data from the user
System.out.println("Enter data bits in the array one by one: ");
for(int i = 0 ; i < size ; i++) {
System.out.println("Enter bit " + (size-i) + ":");
data[i] = scan.nextInt();
}
// take the size of the divisor from the user
System.out.println("Enter the size of the divisor array:");
size = scan.nextInt();
// declaration of the divisor array
int divisor[] = new int[size];
System.out.println("Enter divisor bits in the array one by one: ");
for(int i = 0 ; i < size ; i++) {
System.out.println("Enter bit " + (size-i) + ":");
divisor[i] = scan.nextInt();
}
// Divide the input data by the input divisor and store the result in the rem array
int rem[] = divideDataWithDivisor(data, divisor);
// iterate rem using for loop to print each bit
for(int i = 0; i < rem.length-1; i++) {
System.out.print(rem[i]);
}
System.out.println("\nGenerated CRC code is: ");

for(int i = 0; i < data.length; i++) {


System.out.print(data[i]);
}
for(int i = 0; i < rem.length-1; i++) {
System.out.print(rem[i]);
}
System.out.println();
// we create a new array that contains the original data with its CRC code
// the size of the sentData array with be equal to the sum of the data and the rem arrays length

int sentData[] = new int[data.length + rem.length - 1];


System.out.println("Enter bits in the array which you want to send: ");
for(int i = 0; i < sentData.length; i++) {
System.out.println("Enter bit " +(sentData.length - 1)+ ":");
sentData[i] = scan.nextInt();
}
receiveData(sentData, divisor);
}
// create divideDataWithDivisor() method to get CRC
static int[] divideDataWithDivisor(int oldData[], int divisor[]) {
// declare rem[] array
int rem[] = new int[divisor.length];
int i;
int data[] = new int[oldData.length + divisor.length];
// use system's arraycopy() method for copying data into rem and data arrays
System.arraycopy(oldData, 0, data, 0, oldData.length);
System.arraycopy(data, 0, rem, 0, divisor.length);
// iterate the oldData and exor the bits of the remainder and the divisor
for(i = 0; i < oldData.length; i++) {
System.out.println((i+1) + ".) First data bit is : "+ rem[0]);
System.out.print("Remainder : ");
if(rem[0] == 1) {
// We have to exor the remainder bits with divisor bits
for(int j = 1; j < divisor.length; j++) {
rem[j-1] = exorOperation(rem[j], divisor[j]);
System.out.print(rem[j-1]);
}
}
else {
// We have to exor the remainder bits with 0
for(int j = 1; j < divisor.length; j++) {
rem[j-1] = exorOperation(rem[j], 0);
System.out.print(rem[j-1]);
}
}
// The last bit of the remainder will be taken from the data
// This is the 'carry' taken from the dividend after every step
// of division
rem[divisor.length-1] = data[i+divisor.length];
System.out.println(rem[divisor.length-1]);
}
return rem;
}
// create exorOperation() method to perform exor data
static int exorOperation(int x, int y) {
// This simple function returns the exor of two bits
if(x == y) {
return 0;
}
return 1;
}
// method to print received data
static void receiveData(int data[], int divisor[]) {

int rem[] = divideDataWithDivisor(data, divisor);


// Division is done
for(int i = 0; i < rem.length; i++) {
if(rem[i] != 0) {
// if the remainder is not equal to zero, data is currupted
System.out.println("Currupted data received...");
return;
}
}
System.out.println("Data received without any error.");
}
}

Sample Output:
5. Flow control mechanisms

Aim :

Write a program in Java to implement Go Back N algorithm.

Algorithm

The Program sends the frames from the Client to the Server with checking for missing frames via
sending an acknowledgement.

/*Server Program*/

import java.net.*;
import java.io.*;
import java.util.*;
public class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket server=new ServerSocket(6262);
System.out.println(“Server established.”);
Socket client=server.accept();
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
System.out.println(“Client is now connected.”);
int x=(Integer)ois.readObject();
int k=(Integer)ois.readObject();
int j=0;
int i=(Integer)ois.readObject();
boolean flag=true;
Random r=new Random(6);
int mod=r.nextInt(6);
while(mod==1||mod==0)
mod=r.nextInt(6);
while(true)
{
int c=k;
for(int h=0;h<=x;h++)
{
System.out.print(“|”+c+”|”);
c=(c+1)%x;
}
System.out.println();
System.out.println();
if(k==j)
{
System.out.println(“Frame “+k+” recieved”+”\n”+”Data:”+j);
j++;
System.out.println();
}

else
System.out.println(“Frames recieved not in correct order”+”\n”+” Expected farme:” + j +”\n”+ ”
Recieved frame no :”+ k);
System.out.println();
if(j%mod==0 && flag)
{
System.out.println(“Error found. Acknowledgement not sent. “);
flag=!flag;
j–;
}
else if(k==j-1)
{
oos.writeObject(k);
System.out.println(“Acknowledgement sent”);
}
System.out.println();
if(j%mod==0)
flag=!flag;
k=(Integer)ois.readObject();
if(k==-1)
break;
i=(Integer)ois.readObject();
}
System.out.println(“Client finished sending data. Exiting”);
oos.writeObject(-1);
}
}

/*Client Program*/

import java.util.*;
import java.net.*;
import java.io.*;
public class Client
{
public static void main(String args[]) throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print(“Enter the value of m : “);
int m=Integer.parseInt(br.readLine());
int x=(int)((Math.pow(2,m))-1);
System.out.print(“Enter no. of frames to be sent:”);
int count=Integer.parseInt(br.readLine());
int data[]=new int[count];
int h=0;
for(int i=0;i<count;i++)
{
System.out.print(“Enter data for frame no ” +h+ ” => “);
data[i]=Integer.parseInt(br.readLine());
h=(h+1)%x;
}
Socket client=new Socket(“localhost”,6262);
ObjectInputStream ois=new ObjectInputStream(client.getInputStream());
ObjectOutputStream oos=new ObjectOutputStream(client.getOutputStream());
System.out.println(“Connected with server.”);
boolean flag=false;
GoBackNListener listener=new GoBackNListener(ois,x);
listener=new GoBackNListener(ois,x);
listener.t.start();
int strt=0;
h=0;
oos.writeObject(x);
do
{
int c=h;
for(int i=h;i<count;i++)
{
System.out.print(“|”+c+”|”);
c=(c+1)%x;
}
System.out.println();
System.out.println();
h=strt;
for(int i=strt;i<x;i++)
{
System.out.println(“Sending frame:”+h);
h=(h+1)%x;
System.out.println();
oos.writeObject(i);
oos.writeObject(data[i]);
Thread.sleep(100);
}
listener.t.join(3500);
if(listener.reply!=x-1)
{
System.out.println(“No reply from server in 3.5 seconds. Resending data from frame no ” +
(listener.reply+1));
System.out.println();
strt=listener.reply+1;
flag=false;
}
else
{
System.out.println(“All elements sent successfully. Exiting”);
flag=true;
}
}while(!flag);
oos.writeObject(-1);
}
}

class GoBackNListener implements Runnable


{
Thread t;
ObjectInputStream ois;
int reply,x;
GoBackNListener(ObjectInputStream o,int i)
{
t=new Thread(this);
ois=o;
reply=-2;
x=i;
}
@Override
public void run() {
try
{
int temp=0;
while(reply!=-1)
{
reply=(Integer)ois.readObject();
if(reply!=-1 && reply!=temp+1)
reply=temp;
if(reply!=-1)
{
temp=reply;
System.out.println(“Acknowledgement of frame no ” + (reply%x) + ” recieved.”);
System.out.println();
}
}
reply=temp;
}
catch(Exception e)
{
System.out.println(“Exception => ” + e);
}
}
}

*Client Output

Enter the value of m : 7


Enter no. of frames to be sent:5
Enter data for frame no 0 => 1
Enter data for frame no 1 => 2
Enter data for frame no 2 => 3
Enter data for frame no 3 => 4
Enter data for frame no 4 => 5
Connected with server.
|0||1||2||3||4|

Sending frame:0

Acknowledgement of frame no 0 recieved.

Sending frame:1

Sending frame:2

Sending frame:3

Sending frame:4

Sending frame:5
*/

/*Server Output

Server established.
Client is now connected.
|0||1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||
31||32||33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58
||59||60||61||62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||8
6||87||88||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||1
10||111||112||113||114||115||116||117||118||119||120||121||122||123||124||125||126||0|

Frame 0 recieved
Data:0
Acknowledgement sent

|1||2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31|
|32||33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||5
9||60||61||62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||
87||88||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110|
|111||112||113||114||115||116||117||118||119||120||121||122||123||124||125||126||0||1|

Frame 1 recieved
Data:1
Error found. Acknowledgement not sent.

|2||3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||3
2||33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||
60||61||62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87
||88||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||1
11||112||113||114||115||116||117||118||119||120||121||122||123||124||125||126||0||1||2|

Frames recieved not in correct order


Expected farme:1
Recieved frame no :2
|3||4||5||6||7||8||9||10||11||12||13||14||15||16||17||18||19||20||21||22||23||24||25||26||27||28||29||30||31||32||
33||34||35||36||37||38||39||40||41||42||43||44||45||46||47||48||49||50||51||52||53||54||55||56||57||58||59||60
||61||62||63||64||65||66||67||68||69||70||71||72||73||74||75||76||77||78||79||80||81||82||83||84||85||86||87||8
8||89||90||91||92||93||94||95||96||97||98||99||100||101||102||103||104||105||106||107||108||109||110||111|
|112||113||114||115||116||117||118||119||120||121||122||123||124||125||126||0||1||2||3|

You might also like