83
EX NO:1 STUDY OF WML AND J2ME SIMULATORS AIM To study and understand how the WML and J2ME simulators works. Study of WML: WML stands for Wireless Markup Language WML is an application of XML, which is defined in a document-type definition. WML is based on HDML and is modified so that it can be compared with HTML. WML takes care of the small screen and the low bandwidth of transmission. WML is the markup language defined in the WAP specification. WAP sites are written in WML, while web sites are written in HTML. WML is very similar to HTML. Both of them use tags and are written in plain text format. WML files have the extension ".wml". The MIME type of WML is "text/vnd.wap.wml". WML supports client-side scripting. The scripting language supported is called WMLScript. WML Versions: WAP Forum has released a latest version WAP 2.0. The markup language defined in WAP 2.0 is XHTML Mobile Profile (MP). The WML MP is a subset of the XHTML. A style sheet called WCSS (WAP CSS) has been introduced alongwith XHTML MP. The WCSS is a subset of the CSS2.

mobile computing lab manual

Embed Size (px)

Citation preview

Page 1: mobile computing lab manual

EX NO:1 STUDY OF WML AND J2ME SIMULATORS

AIM

To study and understand how the WML and J2ME simulators works.

Study of WML:

WML stands for Wireless Markup Language WML is an application of XML, which is defined in a document-type definition.

WML is based on HDML and is modified so that it can be compared with HTML.

WML takes care of the small screen and the low bandwidth of transmission.

WML is the markup language defined in the WAP specification.

WAP sites are written in WML, while web sites are written in HTML.

WML is very similar to HTML. Both of them use tags and are written in plain text format.

WML files have the extension ".wml". The MIME type of WML is "text/vnd.wap.wml".

WML supports client-side scripting. The scripting language supported is called WMLScript.

WML Versions:

WAP Forum has released a latest version WAP 2.0. The markup language defined in WAP 2.0 is XHTML Mobile Profile (MP). The WML MP is a subset of the XHTML. A style sheet called WCSS (WAP CSS) has been introduced alongwith XHTML MP. The WCSS is a subset of the CSS2.

Most of the new mobile phone models released are WAP 2.0-enabled. Because WAP 2.0 is backward compatible to WAP 1.x, WAP 2.0-enabled mobile devices can display both XHTML MP and WML documents.

WML 1.x is an earlier technology. However, that does not mean it is of no use, since a lot of wireless devices that only supports WML 1.x are still being used. Latest version of WML is 2.0 and it is created for backward compatibility purposes. So WAP site developers need not to worry about WML 2.0.

WML Decks and Cards:

A main difference between HTML and WML is that the basic unit of navigation in HTML is a page, while that in WML is a card. A WML file can contain multiple cards and they form a deck.

Page 2: mobile computing lab manual

When a WML page is accessed from a mobile phone, all the cards in the page are downloaded from the WAP server. So if the user goes to another card of the same deck, the mobile browser does not have to send any requests to the server since the file that contains the deck is already stored in the wireless device.You can put links, text, images, input fields, option boxes and many other elements in a card.

WML Program Structure:

Following is the basic structure of a WML program:

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card id="one" title="First Card"><p>This is the first card in the deck</p></card>

<card id="two" title="Second Card"><p>Ths is the second card in the deck</p></card>

</wml>

The first line of this text says that this is an XML document and the version is 1.0. The second line selects the document type and gives the URL of the document type definition (DTD).

One WML deck (i.e. page ) can have one or more cards as shown above. We will see complete detail on WML document structure in subsequent chapter.

Unlike HTML 4.01 Transitional, text cannot be enclosed directly in the <card>...</card> tag pair. So you need to put a content inside <p>...</p> as shown above.

WAP Site Design Considerations:

Wireless devices are limited by the size of their displays and keypads. It's therefore very important to take this into account when designing a WAP Site.

Page 3: mobile computing lab manual

While designing a WAP site you must ensure that you keep things simple and easy to use. You should always keep in mind that there are no standard microbrowser behaviors and that the data link may be relatively slow, at around 10Kbps. However, with GPRS, EDGE, and UMTS, this may not be the case for long, depending on where you are located.

The following are general design tips that you should keep in mind when designing a service:

Keep the WML decks and images to less than 1.5KB. Keep text brief and meaningful, and as far as possible try to precode options to minimize the

rather painful experience of user data entry.

Keep URLs brief and easy to recall.

Minimize menu levels to prevent users from getting lost and the system from slowing down.

Use standard layout tags such as <big> and <b>, and logically structure your information.

Don't go overboard with the use of graphics, as many target devices may not support

Develop WAP applications you will need the following:

A WAP enabled Web Server: You can enable your Apache or Microsoft IIS to serve all the WAP client request.

A WAP Gateway Simulator This is required to interact to your WAP server.

A WAP Phone Simulator: This is required to test your WAP Pages and to show all the WAP pages.

You can write your WAP pages using following languages:

Wireless Markup Language(WML) to develop WAP application. WML Script to enhance the functionality of WAP application.

Configuring Web Server:

In normal web applications, MIME type is set to text/html, designating normal HTML code. Images, on the other hand, could be specified as image/gif or image/jpeg, for instance. With this content type specification, the web browser knows the data type that the web server returns.

To make your Apache WAP compatible you have nothing to do very much. You simply need to add support for the MIME types and extensions listed below.

File Extension MIME type

Page 4: mobile computing lab manual

WML (.wml) text/vnd.wap.wml

WMLScript (.wmls) text/vmd.wap.wmlscript

WMLScriptc (.wmlsx) application/vnd.wap.wmlscriptc

WMLC (.wmlc) application/vnd.wap.wmlc

WBMP (.wbmp) image/vnd.wap.wbmp

Configure Apache Web Server for WAP:

Assuming you have Apache Web server installed on your machine. So now we will tell you how to enable WAP functionality in your Apache web server.

So locate Apache's file httpd.conf which is usually in /etc/httpd/conf, and add the following lines to the file and restart the server:

AddType text/vnd.wap.wml .wmlAddType text/vnd.wap.wmlscript .wmlsAddType application/vnd.wap.wmlc .wmlcAddType application/vnd.wap.wmlscriptc .wmlscAddType image/vnd.wap.wbmp .wbmp

In dynamic applications, the MIME type must be set on the fly, whereas in static WAP applications the web server must be configured appropriately.

Configure Microsoft IIS for WAP:

To configure a Microsoft IIS server to deliver WAP content, you need to perform the following:

1. Open the Internet Service Manager console and expand the tree to view your Web site entry. You can add the WAP MIME types to a whole server or individual directories.

2. Open the Properties dialog box by right-clicking the appropriate server or directory, then choose Properties from the menu.

3. From the Properties dialog, choose the HTTP Headers tab, then select the File Types button at the bottom right.

4. For each MIME type listed earlier in the above table, supply the extension with or without the dot (it will be automatically added for you), then click OK in the Properties dialog box to accept your changes.

Page 5: mobile computing lab manual

Installing WAP Gateway Simulator:

There are many WAP Gateway Simulator available on the Internet so download any of them and install on your PC. You would need to run this gateway before starting WAP Mobile simulator.

WAP Gateway will take your request and will pass it to the Web Server and whatever response will be received from the Web server that will be passed to the Mobile Simulator.

Download it from Nokia web site:

Nokia WAP Gateway simulator - Download Nokia WAP Gateway simulator.

Installing WAP Phone Simulator:

There are many WAP Simulator available on the Internet so download any of them and install on your PC which you will use as a WAP client. Here are popular links to download simulator:

Nokia WAP simulator - Download Nokia WAP simulator. WinWAP simulator - Download WinWAP browser from their official website.

NOTE: If you have WAP enabled phone then you do not need to install this simulator. But while doing development it is more convenient and economic to use a simulator.

The WAP Model:

I am giving this section just for your reference, if you are not interested then you can skip this section.

The figure below shows the WAP programming model. Note the similarities with the Internet model. Without the WAP Gateway/Proxy the two models would have been practically identical.

Page 6: mobile computing lab manual

WAP Gateway/Proxy is the entity that connects the wireless domain with the Internet. You should make a note that the request that is sent from the wireless client to the WAP Gateway/Proxy uses the Wireless Session Protocol (WSP). In its essence, WSP is a binary version of HTTP.

A markup language - the Wireless Markup Language (WML) has been adapted to develop optimized WAP applications. In order to save valuable bandwidth in the wireless network, WML can be encoded into a compact binary format. Encoding WML is one of the tasks performed by the WAP Gateway/Proxy.

How WAP Model Works?

When it comes to actual use, WAP works like this:

1. The user selects an option on their mobile device that has a URL with Wireless Markup language (WML) content assigned to it.

2. The phone sends the URL request via the phone network to a WAP gateway, using the binary encoded WAP protocol.

3. The gateway translates this WAP request into a conventional HTTP request for the specified URL, and sends it on to the Internet.

4. The appropriate Web server picks up the HTTP request.

Page 7: mobile computing lab manual

5. The server processes the request, just as it would any other request. If the URL refers to a static WML file, the server delivers it. If a CGI script is requested, it is processed and the content returned as usual.

6. The Web server adds the HTTP header to the WML content and returns it to the gateway.

7. The WAP gateway compiles the WML into binary form.

8. The gateway then sends the WML response back to the phone.

9. The phone receives the WML via the WAP protocol.

10. The micro-browser processes the WML and displays the content on the screen.

Unlike HTML, WML strictly adheres to the XML hierarchical structure, and thus, elements must contain a start tag; any content such as text and/or other elements; and an end tag. Elements have one of the following two structures:

<tag> content </tag> : This form is identical to HTML. <tag />: This is used when an element cannot contain visible content or is empty, such as a line

break. WML document's prolog part does not have any element which has closing element.

Deck & Card Elements

WML Elements Purpose

<!-->  Defines a WML comment

<wml>  Defines a WML deck (WML root)

<head> Defines head information

<meta> Defines meta information

<card> Defines a card in a deck

<access> Defines information about the access control of a deck

Text Elements

WML Elements Purpose

Page 8: mobile computing lab manual

<br> Defines a line break

<p>  Defines a paragraph

<table> Defines a table

<td> Defines a table cell (table data)

<tr> Defines a table row

<pre> Defines preformatted text

Text Formatting Tags

WML Elements Purpose

<b> Defines bold text

<big>  Defines big text

<em> Defines emphasized text

<i> Defines italic text

<small> Defines small text

<strong> Defines strong text

<u> Defines underlined text

Image Elements

WML Elements Purpose

<img> Defines an image

Anchor Elements

WML Elements Purpose

<a> Defines an anchor

<anchor>  Defines an anchor

Page 9: mobile computing lab manual

Event Elements

WML Elements Purpose

<do> Defines a do event handler

<onevent> Defines an onevent event handler

<postfield> Defines a postfield event handler

<ontimer> Defines an ontimer event handler

<onenterforward> Defines an onenterforward handler

<onenterbackward> Defines an onenterbackward handler

<onpick> Defines an onpick event handler

Task Elements

WML Elements Purpose

<go> Represents the action of switching to a new card

<noop> Says that nothing should be done

<prev> Represents the action of going back to the previous card

<refresh> Refreshes some specified card variables.

Input Elements

WML Elements Purpose

<input>  Defines an input field

<select> Defines a select group

<option> Defines an option in a selectable list

<fieldset> Defines a set of input fields

Page 10: mobile computing lab manual

<optgroup> Defines an option group in a selectable list

WML provides various options to let a user enter information through WAP application.First of all, we are going to look at the different options for allowing the user to make straight choices between items. These are usually in the form of menus and submenus, allowing users to drill down to the exact data that they want.

WML <select> Element:

The <select>...</select> WML elements are used to define a selection list and the <option>...</option> tags are used to define an item in a selection list. Items are presented as radio buttons in some WAP browsers. The <option>...</option> tag pair should be enclosed within the <select>...</select> tags.

This element support the following attributes:

Attribute Value Description

iname text Names the variable that is set with the index result of the selection

ivalue text Sets the pre-selected option element

multiple true

false

Sets whether multiple items can be selected. Default is "false"

name text Names the variable that is set with the result of the selection

tabindex number Sets the tabbing position for the select element

title text Sets a title for the list

value text Sets the default value of the variable in the "name" attribute

xml:lang language_code Sets the language used in the element

class class data Sets a class name for the element.

Page 11: mobile computing lab manual

id element ID A unique ID for the element.

Following is the example showing usage of these two elements.

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml12.dtd"><wml><card title="Selectable List"><p> Select a Tutorial : <select> <option value="htm">HTML Tutorial</option> <option value="xml">XML Tutorial</option> <option value="wap">WAP Tutorial</option> </select></p></card></wml>

When you will load this program it will show you following screen:

Once you highlight and enter on the options it will display following screen:

You wan to privide option to select multiple options then set multiple attribute to true as follows:

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml12.dtd">

Page 12: mobile computing lab manual

<wml>

<card title="Selectable List"><p> Select a Tutorial : <select multiple="true"> <option value="htm">HTML Tutorial</option> <option value="xml">XML Tutorial</option> <option value="wap">WAP Tutorial</option> </select></p></card></wml>

This will give you a screen to select multiple options as follows:

WML <input> Element:

The <input/> element is used to create input fields and input fields are used to obtain alphanumeric data from users.

This element support the following attributes:

Attribute Value Description

name text The name of the variable that is set with the result of the user's input

maxlength number Sets the maximum number of characters the user can enter in the field

emptyok true

false

Sets whether the user can leave the input field blank or not. Default is "false"

format Sets the data format for the input field. Default is "*M".

Page 13: mobile computing lab manual

AaNXxMm*fnf

A = uppercase alphabetic or punctuation charactersa = lowercase alphabetic or punctuation charactersN = numeric charactersX = uppercase charactersx = lowercase charactersM = all charactersm = all characters*f = Any number of characters. Replace the f with one of the letters above to specify what characters the user can enternf = Replace the n with a number from 1 to 9 to specify the number of characters the user can enter. Replace the f with one of the letters above to specify what characters the user can enter

size number Sets the width of the input field

tabindex number Sets the tabbing position for the select element

title text Sets a title for the list

type text

password

Indicates the type of the input field. The default value is "text". Password field is used to take password for authentication purpose.

value text Sets the default value of the variable in the "name" attribute

xml:lang language_code Sets the language used in the element

class class data Sets a class name for the element.

id element ID A unique ID for the element.

Following is the example showing usage of this element.

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="Input Fields">

Page 14: mobile computing lab manual

<p> Enter Following Information:<br/> Name: <input name="name" size="12"/> Age : <input name="age" size="12" format="*N"/> Sex : <input name="sex" size="12"/> </p></card>

</wml>

This will provide you following screen to enter required information:

WML <fieldset> Element:

The <fieldset/> element is used to group various input fields or selectable lists.

This element support the following attributes:

Attribute Value Description

title text Sets a title for the list

xml:lang language_code Sets the language used in the element

class class data Sets a class name for the element.

id element ID A unique ID for the element.

Following is the example showing usage of this element.

Page 15: mobile computing lab manual

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml12.dtd">

<wml><card title="Grouped Fields"><p> <fieldset title="Personal Info"> Name: <input name="name" size="12"/> Age : <input name="age" size="12" format="*N"/> Sex : <input name="sex" size="12"/> </fieldset></p></card></wml>

This will provide you following screen to enter required information. This result may differ browser to browser.

WML <optgroup> Element

The <optgroup/> element is used to group various options together inside a selectable list.

This element support the following attributes:

Attribute Value Description

title text Sets a title for the list

xml:lang language_code Sets the language used in the element

class class data Sets a class name for the element.

id element ID A unique ID for the element.

Page 16: mobile computing lab manual

Following is the example showing usage of this element.

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//EN""http://www.wapforum.org/DTD/wml12.dtd">

<wml>

<card title="Selectable List"> <p> <select> <optgroup title="India"> <option value="delhi">Delhi</option> <option value="mumbai">Mumbai</option> <option value="hyderabad">Hyderabad</option> </optgroup> <optgroup title="USA"> <option value="ohio">Ohio</option> <option value="maryland">Maryland</option> <option value="washington">Washingtone</option> </optgroup> </select></p></card>

</wml>

When a user loads above code then it will give two options to be selected:

When users select any of the options then only it will give final options to be selected. So if user selects India then it will show you following options to be selected:

Page 17: mobile computing lab manual

J2ME:

J2ME stands for Java 2, Micro Edition. It is a stripped-down version of Java targeted at devices which have limited processing power and storage capabilities and intermittent or fairly low-bandwidth network connections. These include mobile phones, pagers,wireless devices and set-top boxes among others.

A Sample Wireless Stack would consist of:

Profiles Configurations Java Virtual Machines Host Operating System

What is a J2ME Configuration?

A configuration defines the minimum Java technology that an application developer can expect on a broad range of implementing devices.

J2ME Connected, Limited Device Configuration (CLDC)

specifies the Java environment for mobile phone, pager and wireless devices CLDC devices are usually wireless 160 - 512k of memory available for Java typically has limited power or battery operated network connectivity, often wireless, intermittent, low-bandwidth (9600bps or less)

J2ME Connected Device Configuration (CDC)

Describes the Java environment for digital television set-top boxes, high end wireless devices and automotive telematics systems.

device is powered by a 32-bit processor 2MB or more of total memory available for Java network connectivity, often wireless, intermittent, low-bandwidth (9600bps or less)

Page 18: mobile computing lab manual

These two configurations differ only in their respective memory and display capabilities.

What is a J2ME Profile?

A specification layer above the configuration which describes the Java configuration for a specific vertical market or device type.

J2ME Profiles

J2ME Mobile Information Device Profile (MIDP)

this is the application environment for wireless devices based on the CLDC contains classes for user interface, storage and networking

J2ME Foundation Profile, Personal Basis, Personal and RMI profiles

these are profiles for devices based on the CDC, which are not addressed in this tutorial

Virtual Machines

The CLDC and the CDC each require their own virtual machine because of their different memory and display capabilities. The CLDC virtual machine is far smaller than that required by the CDC and supports less features. The virtual machine for the CLDC is called the Kilo Virtual Machine (KVM) and the virtual machine for the CDC is called the CVM.

Tools

PC | MacOS X | Linux

First make sure that you have the Java 2 SDK, Standard Edition (J2SE SDK), version 1.4.2 (or later). This is essential for development. If you haven't installed it, download it and install it from here http://java.sun.com/j2se/downloads/. You absolutely MUST have the J2SE SDK installed before you install the Java Wireless Toolkit as you will be needing the tools it contains (such as javac) to compile and run your MIDlets.

Then download the J2ME Wireless Toolkit (WTK) which is available free from Sun here - http://java.sun.com/products/j2mewtoolkit/. I'm going to assume that you'll be installing this in the C:\j2mewtk\ directory, if you use another directory, just modify the paths accordingly.

Paths

Java needs to know where all your files are, so we need to add the location of the Java binaries to the system path.

Windows 95/98

Page 19: mobile computing lab manual

Go to Start->Run. Type in command. Then type

SET PATH=%PATH%;C:\j2mewtk\bin

You should also edit your C:\autoexec.bat file to include this line, so you don't have to enter it every single time you restart your computer. After you've done this, you should be able to run the tools included in the Java Wireless Toolkit from any directory on your system.

Windows 2000/XP

Go to Control Panel -> System. Click on the Advanced Tab Click on the Environment Variables button Double-click the PATH variable in the System variables box At the end of the Variable value field, add the path to your J2ME WTK installation - for me this

is something like C:\j2mewtk If you had to install the J2SE SDK too, it's a good idea to add the path for that - for me this is C:\

j2sdk1.4.2_03 and C:\j2sdk1.4.2_03\bin. Here's what my screen looked like.

A good way to test if this worked is to type the preverify command without any arguments in the command line. You should see something like this on your screen.

C:\> preverifyUsage: PREVERIFY.EXE [options] classnames|dirnames ...

where options include:-classpath Directories in which to look for classes-d Directory in which output is written @ Read command line arguments from a text file.

Page 20: mobile computing lab manual

Result:

Thus the study of WML simulator and J2ME simulator is successfully completed.

EX NO:2 DESIGN OF SIMPLE CALCULATOR USING WML

AIM:

To write a program to design the calculator by using WML/J2ME.

ALGORITHM:

STEP 1: Select program Nokia WAP Tool Kit 2.0WAP toolkitSTEP 2: Select Files New WML DeckSTEP 3: Edit a temporary program with correct syntaxSTEP 4: Each cards are linked togetherSTEP 5: Select Files New WML ScriptSTEP 6: In script file we describe the functions of the calculatorSTEP 7: Press show button to show the output.

PROGRAM CODE: Calc.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<!-- Call init routine when deck is first entered,or when card is called --><card id="init">

<onevent type="onenterforward"><go href="calc.wmls#init()"/>

</onevent><p>

Initializing...</p>

</card>

Page 21: mobile computing lab manual

<!-- Display current values and operator --><card id="display">

<p><select>

<option onpick="#num1">$(num1).$(dec1)</option><option onpick="calc.wmls#changeop()">$(operator)</option><option onpick="#num2">$(num2).$(dec2)</option><option onpick="calc.wmls#domath()">Compute</option>

</select></p>

</card><!-- Accept input for value 1 --><card id="num1">

<do type="accept"><go href="#display"/>

</do><!-- Offer easy way to clear values(options key) --><do type="options" label="clear">

<refresh><setvar name="num1" value=""/><setvar name="dec1" value=""/>

</refresh></do><p>

Enter the value:<input name="num1" maxlength="8" format="*N"/><br/>.<br/><input name="dec1" maxlength="3" format="*N"/>

</p></card><!-- Accept input for value 2 --><card id="num2">

<do type="accept"> <go href="#display"/>

</do><!-- Offer easy way to clear values(options key) --><do type="options" label="clear">

<refresh><setvar name="num2" value=""/><setvar name="dec2" value=""/>

</refresh></do>

Page 22: mobile computing lab manual

<p>Enter the value:<input name="num2" maxlength="8" format="*N"/><br/>.<br/><input name="dec2" maxlength="3" format="*N"/>

</p></card><!-- Display result of calculation --><card id="result">

<do type="accept"><go href="#init"/></do><p>

The result of <br/>$(num1) $(operator) $(num2) is:<br/>$(result)

</p></card>

</wml>

PROGRAM CODE: Calc.wmls

// Initialize variablesextern function init(){

WMLBrowser.setVar("num1","");WMLBrowser.setVar("dec1","");WMLBrowser.setVar("num2","");WMLBrowser.setVar("dec2","");WMLBrowser.setVar("operator","+");WMLBrowser.setVar("result",0);WMLBrowser.go("calc.wml#display");

}

// Rotate operator through + - * /extern function changeop(){

var operator = WMLBrowser.getVar("operator");if (operator == "+"){

WMLBrowser.setVar("operator","-");}if (operator == "-")

Page 23: mobile computing lab manual

{WMLBrowser.setVar("operator","x");

}if (operator == "x"){

WMLBrowser.setVar("operator","/");}if (operator == "/"){

WMLBrowser.setVar("operator","+");}WMLBrowser.go("calc.wml#display");

}

// Do the operation specifiedextern function domath() {

var operator = WMLBrowser.getVar("operator");var num1 = WMLBrowser.getVar("num1");var dec1 = WMLBrowser.getVar("dec1");var num2 = WMLBrowser.getVar("num2");var dec2 = WMLBrowser.getVar("dec2");var result = 0;

// Zero values if nothing was enteredif (String.isEmpty(num1)) { num1 = 0; }if (String.isEmpty(dec1)) { dec1 = 0; }if (String.isEmpty(num2)) { num2 = 0; }if (String.isEmpty(dec2)) { dec2 = 0; }

// Assemble full numbers from whole values// and decimalsnum1 = num1 + "." + dec1;num2 = num2 + "." + dec2;

// Do calculation, depending on what operator// was selectedif (operator == "+"){

result = Lang.parseFloat(num1) + Lang.parseFloat(num2);}

if (operator == "-"){

Page 24: mobile computing lab manual

result = num1 - num2;}

if (operator == "x"){

result = num1 * num2;}if (operator == "/"){

result = num1/ num2;}WMLBrowser.setVar("result", result);WMLBrowser.setVar("num2",num2);WMLBrowser.setVar("num1",num1);WMLBrowser.go("calc.wml#result");

}

OUTPUT:

Page 25: mobile computing lab manual
Page 26: mobile computing lab manual

RESULT:

Thus the simple calculator is designed and implemented using WML/J2ME.

Page 27: mobile computing lab manual

Ex.No: 3 DESIGN OF CALENDAR USING WML

AIM:To write a program to design the calender by using WML/J2ME.

ALGORITHM:STEP1: Select program->Nokia WAP Toolkit 2.0-> WAP Toolkit.STEP2: Select files>New->WML Deck.STEP3: Edit a temporary program with correct syntax.STEP4: Create a calendar with the month, date and day.STEP5: Each cards are linked together.STEP6: Compile and show the output.

PROGRAM CODE: Calendar.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<template><do type="prev"><prev/></do>

</template><card id ="card1" title="JAN">

<do type="unknown" label="Next"><go href="#card2"/></do><p>

<table columns="7" align="LCC"><tr>

<td>su</td><td>mo</td><td>tu</td><td>we</td><td>th</td><td>fr</td><td>sa</td>

</tr><tr>

<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td>

</tr><tr>

<td>8</td><td>9</td><td>10</td><td>11</td><td>12</td><td>13</td><td>14</td>

</tr><tr>

<td>15</td><td>16</td><td>17</td><td>18</td><td>19</td><td>20</td><td>21</td>

</tr><tr>

Page 28: mobile computing lab manual

<td>22</td><td>23</td><td>24</td><td>25</td><td>26</td><td>27</td><td>28</td>

</tr><tr>

<td>29</td><td>30</td><td>31</td><td></td><td></td><td></td><td></td>

</tr></table>

</p></card><card id ="card2" title="FEB">

<do type="unknown" label="Next"><go href="#card3"/></do><p>

<table columns="7" align="LCC"><tr>

<td>su</td><td>mo</td><td>tu</td><td>we</td><td>th</td><td>fr</td><td>sa</td>

</tr>

<tr><td></td><td></td><td></td><td>1</td> <td>2</td><td>3</td><td>4</td>

</tr><tr>

<td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td>

</tr><tr>

<td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td>

</tr><tr>

<td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td>

</tr><tr>

<td>26</td><td>27</td><td>28</td><td></td><td></td><td></td><td></td>

</tr></table>

</p></card><card id ="card3" title="MAR">

<do type="unknown" label="Next"><go href="#card4"/></do>

Page 29: mobile computing lab manual

<p><table columns="7" align="LCC">

<tr><td>su</td><td>mo</td><td>tu</td><td>we</td><td>th</td><td>fr</td><td>sa</td>

</tr><tr>

<td></td><td></td><td></td><td>1</td><td>2</td><td>3</td><td>4</td>

</tr><tr>

<td>5</td><td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td>

</tr><tr>

<td>12</td><td>13</td><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td>

</tr><tr>

<td>19</td><td>20</td><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td>

</tr><tr>

<td>26</td><td>27</td><td>28</td><td>29</td><td>30</td><td>31</td><td></td>

</tr></table>

</p></card><card id ="card4" title="APR">

<do type="unknown" label="Next"><go href="#card1"/></do><p>

<table columns="7" align="LCC"><tr>

<td>su</td><td>mo</td><td>tu</td><td>we</td><td>th</td><td>fr</td><td>sa</td>

</tr><tr>

<td></td><td></td><td></td><td></td><td></td><td></td><td>1</td>

</tr><tr>

<td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td><td>8</td>

Page 30: mobile computing lab manual

</tr><tr>

<td>9</td><td>10</td><td>11</td><td>12</td><td>13</td><td>14</td><td>15</td>

</tr><tr>

<td>16</td><td>17</td><td>18</td><td>19</td><td>20</td><td>21</td><td>22</td>

</tr><tr>

<td>23</td><td>24</td><td>25</td><td>26</td><td>27</td><td>28</td><td>29</td>

</tr></table>

</p></card>

</wml>

OUTPUT:

RESULT:

Page 31: mobile computing lab manual

Thus the simple calender is designed and implemented using WML/J2ME.

EX NO:4 DESIGN A TIMER USING WML

AIM:To write a program to design the timer by using WML/J2ME.

ALGORITHM:

STEP1: Select program->Nokia WAP Toolkit 2.0-> WAP Toolkit.STEP2: Select files>New->WML Deck.STEP3: Edit a temporary program with correct syntax.STEP4: In cards set the value of timer.STEP5: Each cards are linked together.STEP6: Compile and show the output.

PROGRAM CODE: timer.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<card id="card1" ontimer="#card2" title="Toolkit Demo"><timer value="50"/><p align="center">

<br/> <br/> <br/><big>

Welcome to ...</big>

</p></card><card id="card2" ontimer="#card3" title="Toolkit Demo">

<timer value="50"/> <p align="center">

<br/> <br/><b>

The Nokia<br/></b><u>

WAP</u>...

</p></card><card id="card3" ontimer="#card1" title="Toolkit Demo">

<timer value="50"/>

Page 32: mobile computing lab manual

<p align="center"><br/> <br/> <br/><big>

<i>Toolkit!

</i></big>

</p></card>

</wml>

OUTPUT:

RESULT:

Thus the timer is designed and implemented using WML/J2ME.

Page 33: mobile computing lab manual

Ex.No: 5 DESIGN A SIMPLE GAME USING WML

AIM:

To write a program to design and implement the simple game using WML

ALGORITHM:

STEP 1:Select programNokiaWAPToolkit2.0WAPToolkit

STEP 2:Select filesnewWMLDeck

STEP 3:Edit a temporary program with correct syntax

STEP 4: Each cards are linked together.

STEP 5:Select filesnewWMLScript.

STEP 6:In script file describe the function picking a random word,build a blank string,pass the values to the browser and evaluate the guess

STEP 7:Compile and show the output.

PROGRAM CODE: hang1.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<card id="init" title="Hangman"><onevent type="onenterforward">

<go href="hang1.wmls#init()"/></onevent><p>

Initializing...</p>

</card><card id="status" title="Hangman">

<do type="accept" label="Guess"><go href="#guess" />

</do><p>

&nbsp;|<br/>

Page 34: mobile computing lab manual

$man<br/><br/>$blank

</p></card><card id="guess" title="Hangman">

<do type="accept"><go href="hang1.wmls#guess()" />

</do><p>

$blank<br/>Guess: <input name="guess" maxlength="1" format="a" />

</p></card><card id="hung" title="Hangman">

<do type="accept" label="Restart"><go href="#init" />

</do><p>

You've been hanged!<br/><br/>Word was:<br/>&nbsp;$word<br/>Your guess:<br/>$blank

</p></card><card id="win" title="Hangman">

<do type="accept" label="Restart"><go href="#init" />

</do><p>

You win!<br/><br/>Word was:<br/>&nbsp;$word<br/>

</p></card>

</wml>

Page 35: mobile computing lab manual

PROGRAM CODE: hang1.wmls

extern function init(){

var words = "animal announce banana doctor elephant giraffe";var idx,x,hang = 0;var blank,word,man = "";

// Pick a random word from listidx = Lang.random(6);word = String.elementAt(words,idx," ");

// Build a blank string (letters all "*") that// is the same length as our wordfor (x = 1; x <= String.length(word); x++ ){

blank = blank + "*";}

// Pass all values to browserWMLBrowser.setVar("word",word);WMLBrowser.setVar("blank",blank);WMLBrowser.setVar("hang",hang);WMLBrowser.setVar("man",man);// Display status cardWMLBrowser.go("hang1.wml#status");

}

// Evaluate current guessextern function guess(){

// Init varsvar x = 0;var temp = "";var correct = false;

var man = "";// Pieces for the hanging man,comma delimitedvar manpieces = " , 0,-,|,-,/, ";// Get current valuesvar word = WMLBrowser.getVar("word");var hang = WMLBrowser.getVar("hang");var blank = WMLBrowser.getVar("blank");

Page 36: mobile computing lab manual

var guess = WMLBrowser.getVar("guess");

// Walk one character at a time through word// If guess = character, reveal character// If guess != character, keep current value// (revealed character or blank)// Also, set "correct" if at least one char found

for (x = 0; x <= String.length(word); x++ ){

if ( String.subString(word,x,1) == guess ){

temp = temp + guess;correct = true;

} else{

temp = temp + String.subString(blank,x,1);}

}

// If letter wasn't found, add one to hanging counterif (! correct) { hang++; }

// Build our hanging manif (hang > 0) {for (x = 1; x <= hang; x++ ){

man = man + String.elementAt(manpieces,x,",");}

}

// Blank the guess so <input> is blankguess = "";

// Pass current values to browserWMLBrowser.setVar("blank",temp);WMLBrowser.setVar("guess",guess);WMLBrowser.setVar("hang",hang);WMLBrowser.setVar("man",man);

// Determine whether player has won (no more // "*" in blank), has lost (6 pieces of man // displayed, or keep playing (else).if ( String.find(temp,"*") == -1 )

Page 37: mobile computing lab manual

{WMLBrowser.go("hang1.wml#win");

}else{

if (hang >= 6){WMLBrowser.go("hang1.wml#hung");}else{

WMLBrowser.go("hang1.wml#status");}

}}

OUTPUT:

RESULT:

Thus the program was written to design and implement the simple game using WML.

Page 38: mobile computing lab manual

Ex.No: 6 ANIMATED IMAGE USING WML

AIM:

To write a program to animate an image using WML

ALGORITHM:

STEP 1:Select program NokiaWAPToolkit2.0 WAPToolkit

STEP 2:Select filesnewWMLDeck

STEP 3:Edit a temporary program with correct syntax

STEP 4:In cards set the timer values for displaying the animation image

STEP 5:Each cards are linked together

STEP 6:Compile and show the output

PROGRAM CODE: animation.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<card id="card1" title="anime1" ontimer="#card2"><timer value="50"/><p align="center">

<img src="sunny.wbmp" alt="" width="50" height="50"/></p><do name="accept" type="accept">

<go href="#card2"/></do>

</card><card id="card2" title="anime2" ontimer="#card1">

<timer value="50"/><p align="center">

<img src="rainy.wbmp" alt="" width="50" height="50"/></p><do name="accept" type="accept">

<go href="#card2"/></do>

</card></wml>

Page 39: mobile computing lab manual

OUTPUT:

RESULT:

Thus the program was written to design and implement the simple game using WML.

Page 40: mobile computing lab manual

Ex.No: 7 DESIGN A PHONEBOOK USING WML

AIM:

To design and implement the currency conversion using wml.

ALGORITHM:

STEP 1:Strat the process.STEP 2:Select program->nokia waptoolkit2.0->wap toolkit.STEP 3:Select files->new->wml deck.STEP4:Edit a temporary program with correct syntax.STEP 5:Create the phonebook with the name, phonebook, location, e-mail and address.STEP 6:Create the link with Fcards that name the details of the persons.STEP 7:Compile and show the output.

PROGRAM CODE: Link.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<template><do type="prev"><prev/></do>

</template> <card id="card1" title="phone book">

<do type="unknown" label="next"><go href="#card2"/></do><p align="left">

<small><b>Name:</b></small><br/>x<br/><small><b>Phone no:</b></small><br/>1111111111<br/><small><b>Location:</b></small><br/>chennai<br/><small><b>E-mail:</b></small><br/>[email protected]

</p></card><card id="card2" title="phone book">

<do type="unknown" label="next"><go href="#card3"/></do><p align="left">

<small><b>Name:y</b></small><br/>y<br/>

Page 41: mobile computing lab manual

<small><b>Phone no:</b></small><br/>22222222<br/>

</p><small><b>Location:</b></small><br/>cbe<br/><small><b>E-mail:</b></small><br/>[email protected]

</p><card id="card3" title="phone book">

<do type="unknown" label="next"><go href="#card1"/></do><p align="left">

<small><b>Name:</b></small><br/>a<br/><small><b>Phone no:</b></small><br/>33333333<br/><small><b>Location:</b></small><br/>Bangalore<br/><small><b>E-mail:</b></small><br/>[email protected]

</p></card>

</wml>

PROGRAM CODE: Phonebook1.wml

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml>

<card id="main" title="Directory"><p>

<anchor>First Name<go href="link.wml"></go>

</anchor><br/><anchor>phone no

<go href="link.wml"></go></anchor><br/><anchor> Location

<go href="link.wml"></go></anchor><br/><anchor> E-Mail

<go href="link.wml"></go></anchor><br/>

</p></card>

</wml>

Page 42: mobile computing lab manual

OUTPUT:

RESULT:

Thus the phonebook is designed and implemented by using WML/J2M3.

Page 43: mobile computing lab manual

Ex.No: 8 SIMULATION OF AUTHENTICATION AND ENCRYPTION TECHNIQUE USED IN GSM

AIM:

To Simulate the Authentication and encryption technique used in GSM

THEORY:

Authentication - Whenever a MS requests access to a network, the network must authenticate the MS. Authentication verifies the identity and validity of the SIM card to the network and ensures that the subscriber is authorized access to the network.

Encryption - In GSM, encryption refers to the process of creating authentication and ciphering crypto-variables using a special key and an encryption algorithm.

Ciphering - Ciphering refers to the process of changing plaintext data into encrypted data using a special key and a special encryption algorithm. Transmissions between the MS and the BTS on the Um link are enciphered.

Ki - The Ki is the individual subscriber authentication key. It is a 128-bit number that is paired with an IMSI when the SIM card is created. The Ki is only stored on the SIM card and at the Authentication Center (AuC). The Ki will never be transmitted across the network on any link.

RAND - The RAND is a random 128-bit number that is generated by the AuC when the network requests to authenticate a subscriber. The RAND is used to generate the Signed Response (SRES) and Kc crypto-variables.

Signed Response - The SRES is a 32-bit crypto-variable used in the authentication process. The MS is challenged by being given the RAND by the network, the SRES is the expected correct response. The MS receives the RAND as a challenge and uses it to calculate the SRES. The SRES is passed up to the network to as a response to the challenge.

A3 Algorithm - The A3 algorithm computes a 32-bit Signed Response (SRES). The Ki and RAND are inputted into the A3 algorithm and the result is the 32-bit SRES. The A3 algorithm resides on the SIM card and at the AuC.

A8 Algorithm - The A8 algorithm computes a 64-bit ciphering key (Kc). The Ki and the RAND are inputted into the A8 algorithm and the result is the 64-bit Kc. The A8 algorithm resides on the ISM card and at the AuC.

Page 44: mobile computing lab manual

COMP128 - A keyed hash function that combines the A3 and A8 algorithms into a single function. The 128-bit Ki and 128-bit RAND are input into the COMP128 which generates a 32-bit SRES and a 54-bit Kc in a single function. COMP128 is weak because it can give away information about the Ki.

Kc - The Kc is the 64-bit ciphering key that is used in the A5 encryption algorithm to encipher and decipher the data that is being transmitted on the Um interface.

A5 - The A5 encryption algorithm is used to encipher and decipher the data that is being transmitted on the Um interface. The Kc and the plaintext data are inputted into the A5 algorithm and the output is enciphered data. The A5 algorithm is a function of the Mobile Equipment (ME) and not a function of the SIM card. The BTS also makes use of the A5 algorithm.

There are three versions of the A5 algorithm:

     A5/1 - The current standard for U.S. and European networks. A5/1 is a stream cipher.

     A5/2 - The deliberately weakened version of A5/1 that is intended for export to non-western countries. A5/2 is a stream cipher.

     A5/3 - A newly developed algorithm not yet in full use. A5/3 is a block cipher.

Triplets - The RAND, SRES, and Kc together are known as the Triplets. The AuC will send these three crypto-variables to the requesting MSC/VLR so it can authenticate and encipher.

RESULT:

Thus the simulation is made on Authentication and encryption.

Page 45: mobile computing lab manual

Ex.No :9 BROWSING THE INTERNET USING MOBILE PHONE SIMULATOR

AIM:

To write a J2ME program for browse the internet using mobile phone simulator.

ALGORITHM:

Step 1: open NetBeans IDEStep 2: from file menu select => new project => Java ME => Mobile Application give any name . as project name Next => Next => FinishStep 3: from file menu select => new file =>MIDP => MIDlet => next => give the Class name As file name => Finish.Step 4: Import the required packages in javax and java.Step 5: Give the class name as AccessUrl and declare necessary variables.Step 6: call connection, pauseApp, destroyApp methods.Step 7: Build and run the code.Step 8: Stop the program

SOURCE CODE:

import java.io.*;import javax.microedition.io.*;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;public class AccessUrl extends MIDlet{

Private Display display;String url = "http://www.roseindia.net/hello.txt";public AccessUrl(){

display = Display.getDisplay(this);}public void startApp(){

try{

connection(url);}catch (IOException e){

System.out.println("IOException " + e);e.printStackTrace();

Page 46: mobile computing lab manual

}}public void pauseApp(){}public void destroyApp(boolean unconditional){}void connection(String url) throws IOException{

StreamConnection sc = null;InputStream is = null;StringBuffer buffer = new StringBuffer();TextBox access;Try{

sc = (StreamConnection)Connector.open(url);is = sc.openInputStream();int chars;while((chars = is.read()) != -1){

buffer.append((char) chars);}System.out.println(buffer.toString());access = new TextBox("Access Text", buffer.toString(), 1024, 0);

}Finally{

if(is != null){

is.close();}if(sc != null){

sc.close();}

}display.setCurrent(access);

}}

OUTPUT:

Page 47: mobile computing lab manual

RESULT:

Thus the application for browse the internet using mobile phone simulator is successfully executed and output is verified.

Ex.No 10 STUDY OF GLOMOSIM SIMULATOR

Page 48: mobile computing lab manual

AIM:

To study and understand the basics of GloMoSim simulator.

STUDY:

Global Mobile Information System Simulator (GloMoSim) is a network protocol simulation software that simulates wireless and wired network systems. GloMoSim is designed using the parallel discrete event simulation capability provided by Parsec, a parallel programming language.[2] GloMoSim currently supports protocols for a purely wireless network. It uses the Parsec compiler to compile the simulation protocols.With GloMoSim we are building a scalable simulation environment for wireless network systems. It is being designed using the parallel discrete-event simulation 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 different simulation layers. This will allow the rapid integration of models developed at different layers by different people. The goal is to build a library of parallelized models that can be used for the evaluation of a variety of wireless network protocols. The proposed protocol stack will include models for the channel, radio, MAC, network, transport, and higher layers.

Network Gridding

The simple approach to designing a network simulation would be to initialize each network node in the simulation as a Parsec entity. We can view different entity initializations as being separate logical processes in the system. Hence each entity initialization requires its own stack space in the runtime. In GloMoSim, we are trying to build a simulation that will scale to thousands of nodes. If we have to instantiate an entity for each node in the runtime, the memory requirements would increase dramatically. The performance of the system would also degrade rapidly. Since there are so many entities in the simulation, the runtime would need to constantly context switch among the different entities in the system. This will cause significant degradation in the performance of the simulation. Hence initializing each node as a separate entity will inherently limit the scalability and performance of the simulation.

To circumvent these problems network gridding was introduced into the simulation. With network gridding, a single entity can simulate several network nodes in the system. A separate data structure representing the complete state of each node is maintained within the entity. Similarly we need to maintain the right level of abstraction. When the simulation code of a particular node is being executed it should not have access to the data structures of the other nodes in the simulation. The network gridding technique means that we can increase the number of nodes in the system while maintaining the same number of entities in the simulation. In fact, the only requirement is that we need only as many entities as the number of processors on which the simulation is being run. Hence if we are running a sequential simulation we need to initialize only one entity in the system. We also don't meet the memory or context switching problems that limit the simulation.

Page 49: mobile computing lab manual

In GloMoSim, each entity represents a geographical area of the simulation. Hence the network nodes which a particular entity represents are determined by the physical position of the nodes.

Suppose we specify the following in the input file:

#SIMULATION-RANGE-X 100SIMULATION-RANGE-Y 100## Number of partitions in x and y range.PARTITION-NUM-X 2PARTITION-NUM-Y 2#

We would now have a simulation are of size (100 * 100). We would also have 4 partitions (each partition is represented by a single entity) in the simulation. So one partition would encompass the square area represented by the coordinates (0, 0), (49, 0), (0, 49), and (49, 49).

Note: The current distribution of GloMoSim only works with a single partition. Since each partition is a regular rectangular region, a partition can have at most eight neighboring partitions. Thus if a network node sends out a message, it has to be sent to at most eight other entities in the simulation. This is much easier then the simple design we talked about originally. If each entity is represented a single network node, broadcasting a message from a node becomes very difficult. The first option is that each entity would have to constantly keep track of the other entities that are within the power range. This becomes difficult if we want to introduce mobility of nodes in the simulation. The second option is that when a node sends out a message, it would be sent to all the other entities in the simulation. The receiving entity could then accept the message if its in the power range of the sender. This is also very inefficient as the number of nodes in the simulation increases. Hence a simple message transmission could become very complicated when we do not use network gridding.

Layered Structure

Since we are building GloMoSim using a layered approach, we would like to have the ability to rapidly integrate models developed at different layers by different people. Hence the simple approach here would seem to be that each layer in the simulation would be represented by a different Parsec entity. We would still have the same problem that we had previously. As the number of layers in the simulation increases, the number of entities in the simulation would also increase. This would lead to scalability and performance problems in the simulation. But this is not as dramatic since there are only a few layers in the simulation. But there are other reasons why we need to aggregate the layers into a single entity.

Often times, different layers of the simulation need to access certain common variables. For example, the upper layers of the simulation need to use the CPU when they are executing any instructions. But CPU is a shared resource among these layers. Hence, before executing any instructions 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 information about the state of the CPU. If these layers are kept as different entities in the simulation we

Page 50: mobile computing lab manual

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

If the layers are kept as different entities, 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 conservative runtime, each entity also has to specify the source and destination set as well as the lookahead values for the entity. Specifying lookahead for an entity can become very complicated. All this creates additional work for the developer who is basically interested in modeling a particular network protocol.

For these reasons, we decided to integrate the various GloMoSim layers into a single entity. Each entity now encompasses all the layers of a simulation. Instead each layer is now implemented as functions in the new design. We provide an initialization function that will be called for each layer of each node at the beginning of the simulation. We provide functions that can be used to send messages between the layers. When a layer receives a particular message, it will automatically invoke a function that is provided by the developer of that particular layer. And based on the contents of the message, the function can then execute the appropriate instructions. At the end of the simulation, a function is also called for each layer of each node. A layer can use this function to collect any relevant statistics. An actual implementation of a particular layer will be shown shortly.

Directory Structure of GloMoSim.

After downloading and upzipping GloMoSim, it should contain the following directories:

/applicaiton contains code for the application layer/bin for executable and input/output files/doc contains the documentation/include contains common include files/mac contains the code for the mac layer/main contains the basic framework design/network contains the code for the network layer/radio contains the code for the physical layer/transport contains the code for the transport layer

You have to compile the files from the main/ directory.

o Run "make depend" to create list of depndencies in the Makefile.o Make sure that the right path for the Parsec compiler is specified in the Makefile for the

"PAR" variable.

o Run "make" to create the executable

You can also use Makent.bat for compiling in batch mode (for NT).To run the simulation you have to go to the bin/ directory. The executable is called "Sim". It taked only one command line paramter, which is an input file. An example input file is CONFIG.IN in bin/ directory.

Page 51: mobile computing lab manual

Run "Sim CONFIG.IN" to run the program. A file called "GLOMO.STAT" is produced at the end of the simulation and contains all the statistics generated by the simulation. Make modifications to CONFIG.IN to vary the parameters for running the simulation.

Description of input file.

This section explains the various parameters which are part of the input file supplied to the GloMoSim executable. In the input file anything following a "#" is treated as a comment. Note that some parameters presented in this section may not be valid in the latest GloMoSim library as we keep updating the library to be configured easily. The "config.in" file included in the distribution should be the most up-to-date configuration file and used as a template file.

The following two parameters stand for the physical terrain in which the nodes are being simulated. For example, the following represents an area of size 100 meters by 100 meters. All range parameters are in terms of meters.

## Terrain Area we are simulating.TERRAIN-RANGE-X 100TERRAIN-RANGE-Y 100#

The following parameter represents the power range of wireless nodes in the simulation. For example, a node can reach any other node within 50 meters of its position.

#POWER-RANGE 50#

The following is a random number seed used to initialize part of the seed of various randomly generated numbers in the simulation. This can be used to vary the seed of the simulation to see the consistency of the results of the simulation.

#SEED 1#

The following parameter represents the maximum simulation time. The numbered portion can be followed by optional letters to modify the simulation time.

For example:100NS - 100 nano-seconds100MS - 100 milli-seconds100S - 100 seconds100 - 100 seconds (default case)

Page 52: mobile computing lab manual

100M - 100 minutes100H - 100 hours100D - 100 days

#SIMULATION-TIME 100M#

The following parameter represents the number of nodes being simulated.

#NUMBER-OF-NODES 12#

The following parameter represents the node placement strategy.

- RANDOM: Nodes are placed randomly within the physical terrain.- UNIFORM: Based on the number of nodes in the simulation, the physical terrain is divided into a number of cells. Within each cell, a node is placed randomly.- GRID: Node placement starts at (0, 0) and are placed in grid format with each node GRID-UNIT away from its neighbors. The number of nodes has to be square of an integer.- FILE: Position of nodes is read from NODE-PLACEMENT-FILE. On each line of the file, the x and y position of a single node is separated by a space.

#NODE-PLACEMENT RANDOM#NODE-PLACEMENT UNIFORM#NODE-PLACEMENT GRID#GRID-UNIT 30

#NODE-PLACEMENT FILE#NODE-PLACEMENT-FILE nodes.input#

The propagation models used for determining if a node is reachable:

Free Space: Predicts received signal strength when the transmitter and receiver have a clear, unobstructed line-of-sight path between them. Received power decays as a function of the T-R separation distance.

Rayleigh Fading Distribution: The Rayleigh Fading Distribution is used to describe the statistical time varying nature of the received envelope of a flat fading signal, or the envelope of an individual multipath component.

Page 53: mobile computing lab manual

Ricean Fading Distribution: When there is a dominant stationary (nonfading) signal component present, such as line-of-sight propagation path, the small-scale fading envelope distribution is Ricean. In such a situation, random multipath components arriving at different angles are superimposed on a stationary dominant signal. At the output of an envelope detector, this has the effect of adding a dc component to the random multipath. The effect of a dominant signal arriving with many weaker multipath signals gives rise to the Ricean distribution. As the dominant signal becomes weaker, the composite signal resembles a noise signal which has an envelope that is Rayleigh. Thus the Ricean distribution degenerates to a Rayleigh distribution when the dominant component fades away. The Ricean distribution is often described in terms of a parameter K which is defined as the ratio between the deterministic signal power and the variance of the multipath. It is given by:

K = (A^2) / (2*sigma^2) or, in terms of dB: K(dB) = 10log((A^2)/(2*sigma^2)) (dB)

The parameter K is known as the Ricean factor and completely specifies the Ricean distribution. As A->0, K->-infinity dB, and as the dominant path decreases in amplitude, the Ricean distribution degenerates to a Rayleigh distribution. The formulas for computing these 3 propagation models were taken from: "Wireless Communication", Chapters 3 & 4, by Theodore S. Rappaport. You can look there for more detailed information about these models.

#PROPAGATION-FUNC FREE-SPACE#PROPAGATION-FUNC RAYLEIGH#PROPAGATION-FUNC RICEAN## RICEAN-K-FACTOR only used for PROPAGATION-FUNC RICEAN# Ratio between deterministic signal power and the variance# of the multipath. (range: -5.0dB to 20.0dB)#RICEAN-K-FACTOR 6.0#

The following parameter represents the bandwidth (in bits per second) at which nodes will transmit messages.#BANDWIDTH 2000000#

For some layers of the simulation, there are multiple protocols built into the simulation. You can specify the protocol that you are interested in by commenting out the protocols that you are not interested in. For example for the radio layer, we have radio with and without capture ability. For the MAC layer we have protocols for CSMA, MACA, and IEEE802.11. For the routing protocol we have Bellmanford and OSPF.

#RADIO-TYPE RADIO-NO-CAPTURE#RADIO-TYPE RADIO-CAPTURE

Page 54: mobile computing lab manual

#MAC-PROTOCOL CSMA#MAC-PROTOCOL MACA#MAC-PROTOCOL 802.11##ROUTING-PROTOCOL BELLMANFORD#ROUTING-PROTOCOL OSPF#NETWORK-PROTOCOL IP#

For the transport layer there are various protocols which can be used individually or concurrently. If you are only interested in simulating a particular protocol, you can place a "NO" for other protocols you are no interested in. This will probably make your simulation a little faster.

#TRANSPORT-PROTOCOL-TCP YES TRANSPORT-PROTOCOL-UDP YES#

The following parameters determine if you are interested in the statistics of a single or multiple layer. By specifying the following parameters as YES, the simulation will provide you with statistics for that particular layer. All the statistics are compiled together into a file called "GLOMO.STAT" that is produced at the end of the simulation. If you need the statistics for a particular node or particular protocol, it is easy to do the filtering. Every single line in the file is of the following format: Node: 9, Layer: RadioNoCapture, Total number of collisions is 0

#TCP-STATISTICS NOUDP-STATISTICS NOROUTING-STATISTICS NONETWORK-LAYER-STATISTICS NOMAC-LAYER-STATISTICS NORADIO-LAYER-STATISTICS YESCHANNEL-LAYER-STATISTICS NO#

The following represent parameters for mobility. If MOBILITY is set to NO, than there is no movement of nodes in the model. For the RANDOM-DRUNKEN model, if a node is currently at position (x, y), it can possibly move to (x-1, y), (x+1, y), (x, y-1), and (x, y+1); as long as the new position is within the physical terrain. For random waypoint, a node randomly selects a destination from the physical terrain. It moves in the direction of the destination in a speed uniformly chosen between MOBILITY-WP-MIN-SPEED and MOBILITY-WP-MAX-SPEED (meter/sec). After it reaches its destination, the node stays there for MOBILITY-WP-PAUSE time period.

Page 55: mobile computing lab manual

The MOBILITY-POSITION-GRANULARITY (in meters) is used for GloMoSim to calculate the frequency of updating the position of each network node.

MOBILITY NONE#Random Waypoint and its required parameters.#MOBILITY RANDOM-WAYPOINT#MOBILITY-WP-PAUSE 30S#MOBILITY-WP-MIN-SPEED 0#MOBILITY-WP-MAX-SPEED 10#MOBILITY TRACE#MOBILITY-TRACE-FILE ./mobility.in#MOBILITY REFERENCE-POINT-GROUP#MOBILITY BBN#MOBILITY PATHLOSS-MATRIX#MOBILITY RANDOM-DRUNKENMOBILITY-POSITION-GRANULARITY 0.5

The following is used to setup applications such as FTP and Telnet.The file will need to contain parameters that will be use to determine connections and other characteristics of the particular application.

#APP-CONFIG-FILE app.conf#

The format of "app.conf" is the following:FTP <source> <dest> <items to send> <start time>TELNET <source> <dest> <session duration> <start time>Tcplib will choose a random value for the following if they are specified as 0:FTP: <items to send>TELNET: <session duration>

4. Statistics Collected by Layers in GloMoSim.

1 Radio Layer Statistics

Total number of packets from macTotal number of packets from channelTotal number of collisionsPower consumed

2. MAC layer statistics

Page 56: mobile computing lab manual

2.1 CSMANumber of packets from networkNumber of packets lost due to buffer overflowNumber of UNICAST packets output to the channelNumber of BROADCAST packets output to the channelNumber of UNICAST packets received clearlyNumber of BROADCAST packets received clearly

2.2 MACANumber of packets from network Number of packets lost due to buffer overflowNumber of UNICAST packets output to the channelNumber of BROADCAST packets output to the channelNumber of UNICAST packets received clearlyNumber of BROADCAST packets received clearlyNumber of RTS Packets sentNumber of CTS Packets sentNumber of RTS Packets gotNumber of CTS Packets gotNumber of Noisy Packets got

2.3 802.11Number of packets from networkNumber of packets lost due to buffer overflowNumber of UNICAST (non-fragmented) packets output to the channelNumber of BROADCAST packets output to the channelNumber of UNICAST packets received clearlyNumber of BROADCAST packets received clearlyNumber of retx packets due to CTS timeoutNumber of retx packets due to ACK timeoutNumber of retx packets due to FRAG ACK timeoutNumber of packets dropped due to exceeding retx timeout countNumber of packets dropped due to exceeding frag. retx timeout count.

3. Network Layer Statistics

3.1 IPNumber of pkts from TCPNumber of pkts to TCPNumber of pkts from UDPNumber of pkts to UDPNumber of pkts from OSPFNumber of pkts to OSPFNumber of TCP pkts dropped due to exceeding ttl or network unreachableNumber of UDP pkts dropped due to exceeding ttl or network unreachable

Page 57: mobile computing lab manual

Number of OSPF pkt dropped due to exceeding ttl or network unreachableAverage Number of hops TCP pkts traversedAverage Number of hops UDP pkts traversedAverage Number of hops OSPF pkts traversed

4. Transport Layer Statistics

4.1 TCPTotal packets sent to network layerData packets sentData packets in sequenceData packets retransmittedAck-only packets sentPure control (SYN|FIN|RST) packets sentWindow update-only packets sentWindow probes sentData packets receivedIn sequence ack packets receivedDuplicate ack packets receivedPure control (SYN|FIN|RST) packets receivedWindow update-only packets receivedWindow probes receivedTotal packets with errorPackets received with ccksum errsPackets received with bad offsetPackets received too short

4.2 UDPNumber of pkts from applicationNumber of pkts to application

5. Application Layer Statistics

5.1 Routing Protocols

5.1.1 BellmanfordTotal number of loop back packetsTotal number of routing table broadcastsTotal number of triggered routing table updatesTotal number of routing table updatesTotal number of packets received from MACTotal number of packets received from Transport LayerTotal number of packets sentTotal number of packets belonging to this nodeTotal hops traversed by own packets

Page 58: mobile computing lab manual

Total number of packets droppedTotal number of packets dropped due to pass hop limitTotal number of packets dropped due to no routing information

5.1.2 OSPFNumber of Hello Packet SentNumber of Hello Packet ReceivedNumber of Times LSA Packet Originated Number of LSA Packet Retransmitted Number of LSA Packet Sent Total Number of LSA Packet Received Number of Link State Ack Packet Sent Number of Link State Ack Packet Received Number of Routing Table Updates

5.2 Traffic Generators

5.2.1 Ftp client and serverTime when session is startedTime when session is closedNumber of bytes sentNumber of bytes received Throughput.

5.2.2 Telnet client and serverTime when session is startedTime when session is closedNumber of bytes sentNumber of bytes received Throughput.

RESULT:

Thus the study of GloMoSim simulator is successfully completed.

Ex.No:11 DESIGN OF CURRENCY CONVERSION USING WML

AIM:

To design and implement the currency conversion using wml.

ALGORITHM:

Page 59: mobile computing lab manual

STEP 1:Strat the process.STEP 2:Select program->nokia waptoolkit2.0->wap toolkit.STEP 3:Select files->new->wml deck.STEP 4:Edit a temporary program with correct syntax.STEP 5:Each cards are linked together.STEP 6:Select files->new->wml script.STEP 7:In script file describe the function of conversion, make the calculation, and return the amount to the browser.STEP 8:Compile and show the output.

PROGRAM:

<?xml version="1.0"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN""http://www.wapforum.org/DTD/wml_1.1.xml"><wml><card id="card1" title="Currency" newcontext="true"> <p> Amount: <input format="N*M" name="amount" title="Amount:"/>From: <select name="from" value="USD" title="From:"> <option value="DEM">German Mark</option> <option value="FRF">French Franc</option> <option value="INR">Indian Rupees</option> <option value="USD">US Dollar</option></select>To: <select name="to" value="FIM" title="To:"> <option value="DEM">German Mark</option> <option value="FRF">French Franc</option> <option value="FIM">Finnish Markka</option> <option value="USD">US Dollar</option></select><br/> = <u>$(conversion)</u><do type="accept" label="Calculate"> <go href="currency.wmls#convert('conversion','$(from)','$(to)',$(amount))"/></do><do type="help" label="Help"> <go href="#card1_help"/></do> </p></card><card id="card1_help" title="Help"> <onevent type="onenterforward">

Page 60: mobile computing lab manual

<go href="currency.wmls#getInfoDate('date')"/> </onevent> <p>The Federal Reserve Bank of New York on $(date). <do type="prev" label="Back"> <prev/> </do> </p></card></wml>

extern function getInfoDate(varName) { WMLBrowser.setVar(varName,"October 29 1998"); WMLBrowser.refresh();}extern function convert(varName,from,to,amount) {var multiplier = 0.0;var returnString = "Not Available";var result;if (from == "DEM") { /* * German Mark */ var DEM_FIM = 0.328728; var DEM_FRF = 0.298331; var DEM_USD = 1.653500; if (to == "DEM") multiplier = 1.0; else if (to == "FIM") multiplier = DEM_FIM; else if (to == "FRF") multiplier = DEM_FRF; else if (to == "USD") multiplier = DEM_USD;} else if (from == "FIM") { /* * Finnish Markka */ var FIM_DEM = 3.042032; var FIM_FRF = 0.907533; var FIM_USD = 5.030000; if (to == "FIM")

Page 61: mobile computing lab manual

multiplier = 1.0; else if (to == "DEM") multiplier = FIM_DEM; else if (to == "FRF") multiplier = FIM_FRF; else if (to == "USD") multiplier = FIM_USD;} else if (from == "FRF") {/* * French Franc*/ var FRF_DEM = 3.351981; var FRF_FIM = 1.101889; var FRF_USD = 5.542500; if (to == "FRF") multiplier = 1.0; else if (to == "FIM") multiplier = FRF_FIM; else if (to == "DEM") multiplier = FRF_DEM; else if (to == "USD") multiplier = FRF_USD;} else if (from == "USD") { /* * US Dollar */ var USD_DEM = 0.604778; var USD_FIM = 0.198807; var USD_FRF = 0.180424; if (to == "USD") multiplier = 1.0; else if (to == "FIM") multiplier = USD_FIM; else if (to == "FRF") multiplier = USD_FRF; else if (to == "DEM") multiplier = USD_DEM;}if (multiplier != 0.0) { /* * Make the calcualtion */ result = amount / multiplier; returnString = String.toString(result);

Page 62: mobile computing lab manual

returnString = String.format("%.2f", returnString);}/* * Return the results to the browser */WMLBrowser.setVar(varName,returnString);WMLBrowser.refresh();}

OUTPUT:

RESULT:

Thus the currency conversion is designed and implemented by using WML/J2ME.

Ex.No: 12 DESIGN OF WEATHER REPORT USING WML

AIM:

To design and implement the currency conversion using wml.

Page 63: mobile computing lab manual

ALGORITHM:

STEP 1:Strat the process.STEP 2:Select program->nokia waptoolkit2.0->wap toolkit.STEP 3:Select files->new->wml deck.STEP 4:Edit a temporary program with correct syntax.STEP 5:Correct the weather report date,day and month.STEP 6:Compile and show the output.

PROGRAM:

<?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml>

<card id="card1" title="Weather Forecast"> <p>

<table columns="3" align="LCC"><tr>

<td>Date</td><td>F&apos;cast</td><td>T &#xB0;C</td></tr><tr>

<td>M 6/7</td><td><img src="rainy.wbmp" alt="rain"/></td><td>25&#xB0;C</td>

</tr><tr>

<td>T 6/8</td><td><img src="partcldy.wbmp" alt="part cldy"/></td>

<td>27&#xB0;C</td></tr><tr>

<td>W 6/9</td><td><img src="cloudy.wbmp" alt="cloudy"/></td>

<td>24&#xB0;C</td></tr><tr>

<td>T 6/10</td><td><img src="rainy.wbmp" alt="rainy"/></td><td>28&#xB0;C</td>

</tr><tr>

Page 64: mobile computing lab manual

<td>F 6/11</td><td><img src="sunny.wbmp" alt="sunny"/></td>

<td>29&#xB0;C</td></tr>

</table></p>

</card> </wml>

OUTPUT:

RESULT:

Thus the weather report is designed and implemented by using WML/J2ME.

Page 65: mobile computing lab manual