MC LAB Experiment File
MC LAB Experiment File
Aim:
To study about WML and J2ME simulator.
Introducton:
Traditonal computng devices use fairly standard hardware confguratons such as displaym
keyboardmlarge amount of memory and permanent storage. However new breed of
computng devices lacs hardware confguraton. J2ME is specially designed for developing
applicatons for small computng devices such as cell phonesm PnA etc.
J2ME Confguratons:
Types:
J2ME Profles:
Profle consists of classes that enable developers to implements features found n a related
group of small computng devices.
Many profle are available . Here we use MInP ( Mobile Informaton nevice Profle) MInP is
used with CLnC confguraton that provides classes for local storagem a user interface and networking
capabilites. Other profles are Game proflem Foundaton proflem RMI profle and many more..
This layer is an implementaton of a Java M irtual Machine that is customized for a partcular
device's host operatng system and supports a partcular J2ME confguraton.
Confguraton layer:
The confguraton layer defnes the minimum set of Java M irtual Machine features and
Java class libraries available on a partcular category of devices. In a waym a confguraton defnes the
commonality of the Java platorm features and libraries that developers can assume to be available on
all devices belonging to a partcular category. This layer is less visible to usersm but is very important to
profle implementers.
Profle layer:
The profle layer defnes the minimum set of applicaton programming interfaces (APIs)
available on a partcular family of devices.
Profles are implemented upon a partcular confguraton. Applicatons are written for a
partcular profle and are thus portable to any device that supports that profle. A device can support
multple profles. This is the layer that is most visible to users and applicaton providers.
MInP layer:
The Mobile Informaton nevice Profle (MInP) is a set of Java APIs that addresses issues such as
user interfacem persistence storagem and networking.
MInlet Programming:
A MInlet is class m which is controlled by the applicaton manager. A MInlet class must contain
three abstract methods that are called by applicaton manager.
public class class-name extends MInlet
{
public void
startApp(){ }
public void
pauseApp() { }
public void destroyApp( unconditonal boolean) { }
}
1) Select a fle system where you want to create a MInlet suite. Right click on itm a popup menu appears.
From the pop up menum select New -> MInlet Suite.
2) Enter the Name of MInlet suite. Click on Next.
3) It gives you two optons.
Allows you to create a new Midlet :
Enter the package and class name . This is the name of a MInlet that is to be created.
Allows you to add existng MInlet :
To add existng MInlet mclick on brows m select the MInlet to be
added. J2ME It also allows you to select icon for the given MInlet. 4)
Click Finish.
AnnING MInlet to a MInlet suite:
1) Select a MInlet suite m to which you want to add Midlet. Right click on itm a pop up menu
appears. Select Edit suite from the popup menu.
2) Click on Ann button to add a new MInlet.
3) Enter name of package and class name.4) Click on OK.
New MInlet is added to your MInlet suite.
nescripton:
Item class is a base class for a number of derived classes that can be contained
within a form class. These derived classes are ChoiceGroup m nateFieldm ImageItemm
StringItem and TextField.
The ChoiceGroup class is used to create check boxes or radio buttons on a form. The
state of an instance of a class derived from the Item class changes whenever user enters data
into the instance msuch as radio button is selected. An ItemListener monitors the events during a
life of the MInlet and traps events that changes in the state of any Item class contained on a
form.
Classes used:
Form Class: It is a container for the other displayable objects that appear on the screen. Any
derived class instance of the Item class can be placed on the instance of Form class.
ChoiceGroup class :
J2ME classifes check boxes and radio buttons as the instance of ChoiceGroup class.
We set the type of choiceGroup instance to EXCLUSIM E to create radio buttons.
ItemStateListener:
Any MInlet that utlizes instances of the Item class withon a form must implement
ItemStateListener and must have an itemStateChanged() method.
nescripton:
are immutable.
A mutable image is drawn on the Canvas using methods available in Graphics class.
An immutable image can be drawn on the screen as well as on Canvas.
where as mutable image is drawn only on the canvas.
Each MInlet has a one instance of the nisplay classm and the nisplay class has a one
derived class called 'displayable'. Everything a MInlet displays on the Screen is created by an
instance of a nisplayable class.
The nisplay class hierarchy is shown below:
public class nisplayable public abstract
class nisplayable public abstract class
Screen extends nisplayable public abstract
class Canvas extends nisplayable
public class Graphics
The screen class is used to create high-level components. the Canvas class is used to gain lowlevel access
to display.
Create an instance of an Image class by calling the createImage() method of the Image class.
private Image img;
img =
Image.createImage
(path);
Once the image is created m it can be drawn on the Canvvs using drawImage() method of
the Graphics class. Graphics.drawImage() drawImage() method takes four parameters.
First parameter is the reference to the image that you want to display.
second and third parameters indicate positon of the image on Canvas.
Fourth parameter specifes the porton of the image bounding box that is placed
at the specifed
co-ordinate
positon.
Example:
Introducton:
The Wireless Markup Language (WML) is the HTML of WAP browsers and is transmitted via
the HTTP protocol.
WML is a markup language built specifcally for communicatng across WAP-based networksm
and is based upon XML (eXtensible Markup Language). Like HnMLm it is at frst glance similar to HTMLm
but is also a much more strictly written language.
To make it possible for web pages to be read from a WAP-enabled devicem WML must be
used. The WML coder determines within the code what parts of the web page are viewable to the
devicem and what is not. For examplem it would not be too advantageous for a 468x60 pixel banner to be
loaded into the small screen of a WAP devicem due to sizem color and bandwidth restraints. Howeverm
certain parts of the text may be made available to the device.
The advantage of the WML language is the fact thatm since it is a subset of XMLm developer's
can easily kill two birds with one stone by building both the web page and wireless device page
simultaneously. While this is stll possible with HnML codem it is certainly not as obvious and
workarounds must be introduced
Although you might not have any plans immediately for creatng a WAP version of your sitem
it is always a good idea to get involved in new technology. All you need to do is make a small site (even
one page) which tells people a bit about your website. In the future you can develop the site further
with things like e-mail and informaton for people to get directly of their phones.
Over the past few months new WAP (Wireless Applicatons Protocol) phones have become
extremely popular and many large websites have created special 'mobile' versions of their site. Many
people predict thatm over the next few yearsm WAP sites will become extremely popular and e-
commerce over mobile phones will be widely available
The main sites which will beneft from WAP are ones providing a service like e-mailm live
sports scores or a calendar service etc. but there are many other uses. For examplem a site giving music
reviews could put their reviews on a WAP site. People could then read the reviews on their mobile
phone while browsing through the Cns in a shop.
WML pages are called nECKS. They are constructed as a set of CARnSm related to each other
with links. When a WML page is accessed from a mobile phonem all the cards in the page are
downloaded from the WAP server. Navigaton between the cards is done by the phone computer -
inside the phone - without any extra access trips to the server.
<?xml version="1.0"?>
!nOCTYPE wml PUBLIC "-//WAPFORUM//nTn WML 1.1//EN"
"http://www.techiwarehouse.com/nTn/wml11.1.xml">
<wml>
<card id="HTML" ttle="HTML Tutorial">
< p> You can learn WML in 30 nays
</p>
</card>
< card id="XML" ttle="XML Tutorial">
< p> You can also learn how to make an WAP based
Page < /p>
</card>
</wml>
As you can see from the examplem the WML document is an XML document. The nOCTYPE is defned to
be wmlm and the nTn is accessed at www.techiwarehouse.org/nTn/wml11.1.xml.
<?xml version="1.0"?>
<!nOCTYPE wml PUBLIC "-//WAP/nTn WML 1.1//EN"
"http://www.wap.org/nTn/wml11.1.xml">
<wml>
<card id="no1" ttle="Card 1">
<p>Hello World!</p>
</card>
<card id="no2" ttle="Card 2">
<p>Welcome to our WAP Tutorial!</p>
</card>
</wml>
WML TAGS
WAP homepages are not very diferent from HTML homepages. The markup language used
for WAP is WML (Wireless Markup Language). WML uses tags - just like HTML - but the syntax is stricter
and conforms to the XML 1.0 standard. WML pages have the extension *.WMLm just like HTML pages
have the extension *.HTML
WML is mostly about text. Tags that would slow down the communicaton with
handheld devices are not a part of the WML standard. The use of tables and images is strongly
restricted.
Since WML is an XML applicatonm all tags are case sensitve (<wml> is not the same as </WML>)m and
all tags must be properly closed.
CONCLUSION
Wap's designed is fexible for client's minimal resources such as computng power and memory
storage.WAP is programmed in wireless markup language WML (applicaton of
XML) and WMLScript (WAP's version JavaScript) which is embedded in client's mobile. WML provides a
simple event mechanism that allows diferent content to be displayed. User actonsm
such as pressing a keym can be ted to scripts that cause changes in content. The WML browser also has
this tmer functon that can load a diferent page or trigger the change of variables when the tme is up.
This provide great fexibility than the statc content that HTML can deliver.
2.CALCULATOR
CODING:
import javax.microediton.midlet.*;
import javax.microediton.lcdui.*;
public Calculator()
a=new TextField("n1:"m""m30mTextField.ANY);
b=new TextField("n2:"m""m30mTextField.ANY);
add=new Command("Add"mCommand.OKm1);
sub=new Command("Sub"mCommand.OKm2);
mul=new Command("Mul"mCommand.OKm3);
exit=new Command("Exit"mCommand.EXITm0);
display=nisplay.getnisplay(this);
form=new Form("Calculator");
form.append(a);
form.append(b);
form.addCommand(add);
form.setCommandListener(this);
form.addCommand(sub);
form.setCommandListener(this);
form.addCommand(mul);
form.setCommandListener(this);
form.addCommand(exit);
form.setCommandListener(this);
display.setCurrent(form);
String n1=a.getString();
String n2=b.getString();
if(c==add)
display=nisplay.getnisplay(this);
int res=Integer.parseInt(n1)+Integer.parseInt(n2);
alert=new Alert("result"mres+""mnullmAlertType.INFO);
alert.setTimeout(Alert.FOREM ER);
display.setCurrent(alertmform);
if(c==sub)
display=nisplay.getnisplay(this);
int res=Integer.parseInt(n1)-Integer.parseInt(n2);
alert=new Alert("result"mres+""mnullmAlertType.INFO);
alert.setTimeout(Alert.FOREM ER);
display.setCurrent(alertmform);
if(c==mul)
display=nisplay.getnisplay(this);
int res=Integer.parseInt(n1)*Integer.parseInt(n2);
alert=new Alert("result"mres+""mnullmAlertType.INFO);
alert.setTimeout(Alert.FOREM ER);
display.setCurrent(alertmform);
if(c==exit)
destroyApp(false);
notfynestroyed();
}}}
OUTPUT:
3.CALENDER
COnING:
import javax.microediton.lcdui.*;
import javax.microediton.midlet.*;
Form displayForm;
nateField date;
public PhoneCalender()
display=nisplay.getnisplay(this);
exitCommand=new Command("exit"mCommand.SCREENm1);
displayForm.append(date);
displayForm.addCommand(exitCommand);
displayForm.setCommandListener(this);
displayForm.setItemStateListener(this);
display.setCurrent(displayForm);
{}
if(c==exitCommand)
destroyApp(false);
notfynestroyed();
}
OUTPUT:
4.TIMERTEMPLATE
CODING:
import java.utl.*;
import javax.microediton.midlet.*;
import javax.microediton.lcdui.*;
public TimerTemplate()
display=nisplay.getnisplay(this);
fmMain=new Form("TimerTest");
fmMain.append("Waitng...........\n");
cmExit=new Command("Exit"mCommand.EXITm1);
cmStop=new Command("Stop"mCommand.STOPm2);
fmMain.addCommand(cmExit);
fmMain.addCommand(cmStop);
fmMain.setCommandListener(this);
tm=new Timer();
tt=new TestTimerTask();
tm.schedule(ttm5000);
display.setCurrent(fmMain);
if(c==cmStop)
tm.cancel();
else if(c==cmExit)
destroyApp(false);
notfynestroyed();
}
OUTPUT:
5.SIMPLE GAME
CODING:
import javax.microediton.midlet.*;
import javax.microediton.lcdui.*;
import java.utl.Timer;
import java.utl.TimerTask;
Ball b1mb2;
BallCanvas bc;
nisplay display;
public Bouncing()
System.out.println("Bouncing ball");
try
bc=new BallCanvas();
display=nisplay.getnisplay(this);
display.setCurrent(bc);
}
catch(Excepton e)
System.out.println(e);
Graphics g1;
g1=g;
Graphics getGraphics()
return(g1);
TimerTask t;
Timer tmer;
Graphics g;
BallCanvas bc;
public Ball(int xmint ymint rmint ixmint iymint smint rdmint grmint bmGraphics g1mint mxmint mymBallCanvas bc1)
System.out.println("Ball");
maxx=mx;
maxy=my;
incx=ix;
incy=iy;
red=rd;
green=gr;
blue=b;
xb=false;
yb=false;
redius=r;
ox=x;
oy=y;
fag=false;
bc=bc1;
g1=g;
tmer=new Timer();
tmer.schedule(new Bounce()m(long)0m(long)s);
if((ox+redius)>=maxx)
xb=true;
if(ox<=0)
xb=false;
if((oy+redius)>=maxy)
yb=true;
if(oy<=0)
yb=false;
if(xb==false)
prev1=ox;
ox+=incx;
else
prev1=ox;
ox-=incx;
if(yb==false)
prev2=oy;
oy+=incy;
else
prev2=oy;
oy-=incy;
bc.repaint();
if(fag==false)
{
bc.getGraphics().setColor(0m0m0);
bc.getGraphics().fllRect(0m0mbc.getWidth()mbc.getHeight());
fag=true;
bc.getGraphics().setColor(0m0m0);
bc.getGraphics().fllArc(prev1mprev2mrediusmrediusm0m360);
bc.getGraphics().setColor(redmgreenmblue);
bc.getGraphics().fllArc(oxmoymrediusmrediusm0m360);
try
wait(20);
catch(Excepton e)
paint();
}
OUTPUT:
6.ANIMATION
CODING:
import javax.microediton.lcdui.*;
import javax.microediton.midlet.*;
sweeper.start();
sweeper.addCommand(new Command("Exit"mCommand.EXITm0));
sweeper.setCommandListener(new CommandListener()
sweeper.stop();
notfynestroyed();
});
nisplay.getnisplay(this).setCurrent(sweeper);
}
class SweepCanvas extends Canvas implements Runnable
public SweepCanvas()
mTheta=0;
mBorder=10;
mnelay=50;
mTrucking=true;
t.start();
mTrucking=false;
int width=getWidth();
int height=getHeight();
g.setGrayScale(255);
g.fllRect(0m0mwidth-1mheight-1);
int x=mBorder;
int y=mBorder;
int w=width-mBorder*2;
int h=height-mBorder*2;
for(int i=0;i<8;i++)
g.setGrayScale((8-i)*32-16);
g.fllArc(xmymwmhmmTheta+i*10m10);
g.fllArc(xmymwmhm(mTheta+180)3360+i*10m10);
while(mTrucking)
mTheta=(mTheta+1)3360;
repaint();
try
Thread.sleep(mnelay);
catch(InterruptedExcepton ie)
}
OUTPUT:
7.PERSONAL PHONE BOOK
CODING:
import javax.microediton.midlet.*;
import javax.microediton.lcdui.*;
public PhoneBook()
next=new Command("Next"mCommand.SCREENm2);
exit=new Command("Exit"mCommand.SCREENm2);
New=new Command("New"mCommand.SCREENm2);
display=nisplay.getnisplay(this);
name.addCommand(next);
name.setCommandListener(this);
number.addCommand(New);
number.setCommandListener(this);
number.addCommand(exit);
number.setCommandListener(this);
display.setCurrent(name);
notfynestroyed();
String label=c.getLabel();
if(label.equals("Exit"))
System.out.println("Name="+name.getString()+"Number="+number.getString());
destroyApp(false);
else if(label.equals("Next"))
number.setString("");
display.setCurrent(number);
else if(label.equals("New"))
display.setCurrent(name);
System.out.println("Name="+name.getString()+"Number="+number.getString());
name.setString("");
}
OUTPUT:
8.AUTHENTICATION AND ENCRYPTION TECHNIQUE
CODING:
import javax.microediton.midlet.MInlet;
import javax.microediton.lcdui.*;
public LoginMidlet()
userName=new TextField("LoginIn:"m""m10mTextField.ANY);
password=new TextField("password:"m""m10mTextField.PASSWORn);
cancel=new Command("Cancel"mCommand.CANCELm2);
login=new Command("Login"mCommand.OKm2);
display=nisplay.getnisplay(this);
form.append(userName);
form.append(password);
form.addCommand(cancel);
form.setCommandListener(this);
form.addCommand(login);
form.setCommandListener(this);
display.setCurrent(form);
{}
notfynestroyed();
if(name.equals("qm")&&password.equals("j2"))
menu();
else
tryAgain();
}}
services.append("Check Mail"mnull);
services.append("Compose"mnull);
services.append("Addresses"mnull);
services.append("Optons"mnull);
services.append("Sign out"mnull);
display.setCurrent(services);
error.setTimeout(Alert.FOREM ER);
userName.setString("");
password.setString("");
display.setCurrent(errormform);
String label=c.getLabel();
if(label.equals("Cancel")) {
destroyApp(true);
else if(label.equals("Login"))
validateUser(userName.getString()mpassword.getString());
}}
OUTPUT:
9.SIMULATION
10.Study of GlomoSim Simulator
Aim:
1. Introducton to GloMoSim.
1. Introducton
With GloMoSim we are building a scalable simulaton environment for wireless network systems. It is
being designed using the parallel discrete-event simulaton capability provided by Parsec.
Most network systems are currently built using a layered approach that is similar to the OSI seven layer
network architecture. The plan is to build GloMoSim using a similar layered approach. Standard APIs
will be used between the diferent simulaton layers. This will allow the rapid integraton of models
developed at diferent layers by diferent people. The goal is to build a library of parallelized models
that can be used for the evaluaton of a variety of wireless network protocols. The proposed protocol
stack will include models for the channelm radiom MACm networkm transportm and higher layers.
The simple approach to designing a network simulaton would be to initalize each network node in the
simulaton as a Parsec entty. We can view diferent entty initalizatons as being separate logical
processes in the system. Hence each entty initalizaton requires its own stack space in the runtme. In
GloMoSimm we are trying to build a simulaton that will scale to thousands of nodes. If we have to
instantate an entty for each node in the runtmem the memory requirements would increase
dramatcally. The performance of the system would also degrade rapidly. Since there are so many
enttes in the simulatonm the runtme would need to constantly context switch among the diferent
enttes in the system. This will cause signifcant degradaton in the performance of the simulaton.
Hence initalizing each node as a separate entty will inherently limit the scalability and performance of
the simulaton.
To circumvent these problems network gridding was introduced into the simulaton. With network
griddingm a single entty can simulate several network nodes in the system. A separate data structure
representng the complete state of each node is maintained within the entty. Similarly we need to
maintain the right level of abstracton. When the simulaton code of a partcular node is being
executed it should not have access to the data structures of the other nodes in the simulaton. The
network gridding technique means that we can increase the number of nodes in the system while
maintaining the same number of enttes in the simulaton. In factm the only requirement is that we
need only as many enttes as the number of processors on which the simulaton is being run. Hence if
we are running a sequental simulaton we need to initalize only one entty in the system. We also
don't meet the memory or context switching problems that limit the simulaton.
In GloMoSimm each entty represents a geographical area of the simulaton. Hence the network nodes
which a partcular entty represents are determined by the physical positon of the nodes.
#
SIMULATION-RANGE-X 100
SIMULATION-RANGE-Y 100
#
# Number of parttons in x and y range.
PARTITION-NUM-X 2
PARTITION-NUM-Y 2
#
We would now have a simulaton are of size (100 * 100). We would also have 4 parttons (each
partton is represented by a single entty) in the simulaton. So one partton would encompass the
square area represented by the coordinates (0m 0)m (49m 0)m (0m 49)m and (49m 49).
Since we are building GloMoSim using a layered approachm we would like to have the ability to rapidly
integrate models developed at diferent layers by diferent people. Hence the simple approach here
would seem to be that each layer in the simulaton would be represented by a diferent Parsec entty.
We would stll have the same problem that we had previously. As the number of layers in the
simulaton increasesm the number of enttes in the simulaton would also increase. This would lead to
scalability and performance problems in the simulaton. But this is not as dramatc since there are only
a few layers in the simulaton. But there are other reasons why we need to aggregate the layers into a
single entty.
Ofen tmesm diferent layers of the simulaton need to access certain common variables. For examplem
the upper layers of the simulaton need to use the CPU when they are executng any instructons. But
CPU is a shared resource among these layers. Hencem before executng any instructons a layer has to
make sure that the CPU is free. Hence the upper layers need to have access to common variables
which will provide informaton about the state of the CPU. If these layers are kept as diferent enttes
in the simulaton we don't have a way of accessing shared variables. Besides we don't want to use any
global variables as they can create problems for parallel executon.
If the layers are kept as diferent enttesm each layer also has to explicitly keep track of the "ename"
value for the upper and lower layers. These "ename" values are needed for message passing among the
various layers. For parallel conservatve runtmem each entty also has to specify the source and
destnaton set as well as the lookahead values for the entty. Specifying lookahead for an entty can
become very complicated. All this creates additonal work for the developer who is basically interested
in modeling a partcular network protocol.
For these reasonsm we decided to integrate the various GloMoSim layers into a single entty. Each entty
now encompasses all the layers of a simulaton. Instead each layer is now implemented as functons in
the new design. We provide an initalizaton functon that will be called for each layer of each node at
the beginning of the simulaton. We provide functons that can be used to send messages between the
layers. When a layer receives a partcular messagem it will automatcally invoke a functon that is
provided by the developer of that partcular layer. And based on the contents of the messagem the
functon can then execute the appropriate instructons. At the end of the simulatonm a functon is also
called for each layer of each node. A layer can use this functon to collect any relevant statstcs. An
actual implementaton of a partcular layer will be shown shortly.
Afer downloading and upzipping GloMoSimm it should contain the following directories:
You can also use Makent.bat for compiling in batch mode (for NT).
To run the simulaton you have to go to the bin/ directory. The executable is called "Sim". It taked only
one command line paramterm which is an input fle. An example input fle is CONFIG.IN in bin/ directory.
Run "Sim CONFIG.IN" to run the program. A fle called "GLOMO.STAT" is produced at the end of the
simulaton and contains all the statstcs generated by the simulaton. Make modifcatons to CONFIG.IN
to vary the parameters for running the simulaton.
This secton explains the various parameters which are part of the input fle supplied to the GloMoSim
executable. In the input fle anything following a "#" is treated as a comment. Note that some
parameters presented in this secton may not be valid in the latest GloMoSim library as we keep
updatng the library to be confgured easily. The "confg.in" fle included in the distributon should be
the most up-to-date confguraton fle and used as a template fle.
The following two parameters stand for the physical terrain in which the nodes are being simulated. For
examplem the following represents an area of size 100 meters by 100 meters. All range parameters are in
terms of meters.
#
# Terrain Area we are simulatng.
TERRAIN-RANGE-X 100
TERRAIN-RANGE-Y 100
#
The following parameter represents the power range of wireless nodes in the simulaton. For examplem a
node can reach any other node within 50 meters of its positon.
#
POWER-RANGE 50
#
The following is a random number seed used to initalize part of the seed of various randomly generated
numbers in the simulaton. This can be used to vary the seed of the simulaton to see the consistency of
the results of the simulaton.
#
SEEn 1
#
The following parameter represents the maximum simulaton tme. The numbered porton can be
followed by optonal letters to modify the simulaton tme.
For example:
100NS - 100 nano-seconds
100MS - 100 milli-seconds
100S - 100 seconds
100 - 100 seconds (default case)
100M - 100 minutes
100H - 100 hours
100n - 100 days
#
SIMULATION-TIME 100M
#
#
NUMBER-OF-NOnES 12
#
Conclusion:
Here the glomo simulator has been evaluated with the range of small tme manipulaton.