Home > Articles

Wireless Programming

This chapter is from the book

This chapter is from the book

WAP/WML/WMLScript

The most common standard of data transfer and presentation for a handheld device involves the combination of Wireless Application Protocol (WAP) with Wireless Markup Language (WML). Although WAP can be used with other forms of presentation, its coders primarily designed it to be used with WML.

WAP

Because of the small size of PCS devices, and because they operate with much less bandwidth or speed, than the rest of the Internet, a special protocol was necessary to redefine how they handle data transmission. This protocol needed to take into consideration that the average user views information on a screen with as little as five lines. When compared to a computer screen, this is a colossal difference. In addition to size, the typical PCS device does not support the same type of navigation that a desktop browser uses. Typically, you perform all PCS navigation with a list of options, or by pushing a button on the PCS device. To illustrate, compare CNN's top news page viewed on a cell phone (Figure 3.1) to the same page viewed with Internet Explorer on a desktop machine (Figure 3.2).

Figure 3.1Figure 3.1 PCS browsing.

Figure 3.2Figure 3.2 Desktop browsing.

The difference is dramatic. Color, layout, format, and fonts are severely restricted in most PCS devices. This is where WAP becomes important.

When a device connects to the Internet, several actions occur to bring the Web site to the requesting device. The device actually connects through a series of devices that incorporate different parts of the WAP application stack. The following outlines what happens when you request a Web page using WAP:

  1. The device is turned on and accesses the Internet application via the minibrowser, a program that simply interprets the downloaded information and enables the user to interact with the presented data.

  2. The device searches for and connects to service.

  3. A Web site is selected.

  4. A request is sent to gateway server using WAP.

  5. The gateway server retrieves information as HTML, and converts it to the appropriate language.

  6. The converted data is sent to the PCS device.

In other words, the process of fetching Internet content to a Web-enabled PCS device is handled in two parts. The first part requires the gateway server to connect to the Web server and retrieve the actual content of the Web page. The second part converts this content to a format compatible with the PCS device, and then transfers this content to the device. This is where WAP becomes an important part of the process.

The WAP application stack is made up of six different parts, as illustrated in Figure 3.3. Each part has its specific function, and it is important that you understand each part. The following will break down these parts so that you can get a better insight into PCS.

Figure 3.3Figure 3.3 WAP application stack.

  • Wireless Application Environment (WAE)—This part of the stack defines the programming and scripting used for wireless applications. One of the most common of languages is WMLScript, which is discussed later in this chapter.

  • Wireless Session Protocol (WSP)—This part is responsible for the type of communication established with the PCS device. It defines whether the session is connection-oriented or connectionless. For example, because of the low impact its lost data will have on the resulting communication, a transfer of music would be connectionless. However, for more critical uses, guaranteed two-way communication is required. (This is similar to UDP versus TCP in traditional networking.)

  • Wireless Transaction Session Protocol (WTSP)—This part of WAP is used to classify data flow as reliable one-way, reliable two-way, or unreliable one-way.

  • Wireless Transport Layer Security (WTLS)—This layer is the security part of WAP. It provides encryption, authentication, data integrity checks, and more.

  • Wireless Datagram Protocol (WDP)—This part of WAP is where the data is broken down for the actual carrier. Because of the many different types of data transfer methods, the WDP ensures standardization, so any carrier can be used to transfer wireless data as long as it is compatible with WAP.

  • Network carriers—This is the carrier method (also called a bearer) responsible for delivering the data to the PCS device. There are numerous carriers, but any will work as long as it can link to the WDP layer.

Once the data maneuvers through this stack, The PCS device processes it and presents it on the screen with a minibrowser. This can be as basic as maneuvering through a menu, or it can be as complex as playing an interactive game.

WML

Now that you have a basic understanding of WAP's purpose, let's examine the actual data and how it is presented. As mentioned before, WML is a markup language based on XML. It is not a programming language such as COBOL, Java, or even VBScript. It is only a formatting language that defines text and object placement and appearance. For example, if you wanted to define a word as bold, you would use the following:

<b>Hi!</b>.

This would result in "Hi!".

However, WML also defines how navigation is performed, and how information is linked. The Internet most of us are familiar with uses Web pages to present data. These pages are actually files that sit on a remote host, and are downloaded to your client computer to be viewed in a browser. PCS devices use the same concept, but instead of viewing Web pages, you view "cards."

The following code is a sample card that forms the screen shot in Figure 3.4.

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.2//ED"
http://www.wapforum.org/DTD/wml12.dtd>
<wml>
   <card>
     <p>
        -Top Stories-<br/>
        <a accesskey = "1" href=http://mobile.cnn.com/sharon.wml
title="sharon">Sharon announces...</a><br/>
        <a accesskey = "2" href=http://mobile.cnn.com/bush.wml
title="bush">Bush presses Congress...</a><br/>
        <a accesksey = "3" href=http://mobile.cnn.com/colombia.wml
title="colombia">Colombia targets...</a><br/>
        <a accesskey = "4" href=http://mobile.cnn.com/ex-priest.wml
title="ex-priest">Ex-priest gives...</a><br/>
     </p>
   </card>
</wml>

Figure 3.4Figure 3.4 Display of a PCS card.

After looking at the sample code, do you see any similarity between it and XHTML? You should. In fact, WML is a brother to XHTML, and as such, has inherited all its rules. Note that each tag has a matching closing tag, or in the case of <br/>, is closed by the trailing backslash (/). Also, note the lowercase lettering and use of quotes. These are all requirements of XHTML that have been integrated into WML.

At this point, you might be wondering why PCS devices do not use XHTML instead of creating a new standard. The answer is that XHTML is too bloated for most PCS devices. Because of the number of properties and settings that XHTML can support, a browser that is XHTML-compatible takes up more memory than the relatively basic WML browser. Because a PCS device is limited in memory and size, it cannot support XHTML.

WMLScript

A developer can incorporate any number of programming or scripting languages into a Web page. These languages can be classified as either server-side scripting or client-side scripting. Server-side scripting typically handles complex issues or processes that must remain secure because of database connectivity. Client-side scripting, on the other hand, is typically used for simple programming needs, which often includes form validation and presentation enhancements, like trailing mouse images. However, client-side applications can also consist of complex programming.

Because of the rich variety of client-side programming, browsers that support programming languages like JavaScript must know how to handle all possible programming functions. This requirement means a browser that supports JavaScript must be large and cumbersome, which becomes an issue for space-starved PCS devices. In addition to the bloated browser software, an advanced client-side application must be downloaded to the browser every time it is used. Although the typical desktop computer can handle a 60K file with no problem, a file this size can be expensive to the PCS end user because of the limited bandwidth. This is why WMLScript has become the primary tool for PCS client-side programming.

WMLScript is very similar to JavaScript. It includes many of the same logical functions and syntax. However, WMLScript (WMLS) is less complex, and is optimized for PCS devices. For example, in the desktop world that uses JavaScript, if a programmer wants to alert a user that an action was invalid, she would use an alert('Stop') command. This would cause a message similar to Figure 3.5 to pop up on the screen.

Figure 3.5Figure 3.5 JavaScript alert.

This type of immediate alert is not possible using current PCS devices. Whereas a desktop browser supports dynamic screens that appear on top of another screen, the PCS environment does not. To alert a user to an invalid entry, the value must be sent to a script file. The file must then detect the error and call another file, which in turn sends the alert to the screen of the PCS device. Finally, the acknowledgement will bounce back to the originating card, where the invalid entry was made. As you can see, the process is not complex, just lengthy.

To illustrate how WML works with WMLS, let's examine a sample application. The following is the WML and WMLS page used to create a sample addition program.

Add.wml
_______________________________________________________________________
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//PHONE.COM//DTD WML 1.3//EN" 
"http://www.phone.com/dtd/wml13.dtd">
<!-- WML file created by Openwave SDK -->
<wml>
   <card id="first" >
      <onevent type="onenterforward">
          <refresh>
             <setvar name="firstVal" value=""/>
             <setvar name="secondVal" value=""/>
          </refresh>
       </onevent>
      <p>
         <do type="accept" label="Plus">
            <go href="#second"/>
         </do>
          Add two numbers...
        First #:
          <input type="text" name="firstVal" format="*N"/>
      </p>
   </card>
   <card id="second">
      <onevent type="onenterforward">
         <refresh>
          <setvar name="ans" value=""/>
         </refresh>
     </onevent>
      <p>
         <do type="accept" label="Add">
            <go href="addit.wmls#addNum()"/>
         </do>
         Second number
         <input type="text" name="secondVal" format="*N"/>
        $firstVal + ______ =
      </p>
   </card>

   <card id="answer" title="answer">
     <p>
         $firstVal + $secondVal = $ans
      </p>
   </card>
</wml>
_______________________________________________________________________
addIt.wmls
_______________________________________________________________________
extern function addNum(){
   //grab incoming values
   var fv = WMLBrowser.getVar("firstVal");
   var sv = WMLBrowser.getVar("secondVal");
   var val = WMLBrowser.getVar("ans");

   //convert values to integers
   var fvNum= Lang.parseInt(fv);
   var svNum = Lang.parseInt(sv);

   //add values
   var valNum = fvNum + svNum;

   //set answer and return to answer card in deck
   WMLBrowser.setVar("ans", valNum);
   WMLBrowser.go("#answer");
}

Figure 3.6 shows screenshots of what this would look like using Openwave's SDK WAP 5.

Figure 3.6Figure 3.6 WAP samples.

NOTE

These are three different screens, using four different files. This same application on a desktop browser such as Internet Explorer could be accomplished with one file and on one screen.

WML differs from any other formatting language. As you can see in the code sample, the WML file is actually a series of cards. Each card represents a possible screen, but is linked to the other cards in the deck, or group of cards. You can also see the proper implementation of XHTML and XML rules. Quotes, closed tags, and lowercase attributes are all used consistently within this file.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020