Enterprise J2ME Developing Mobile Java Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Enterprise J2ME Developing Mobile Java Applications [Electronic resources] - نسخه متنی

Michael Juntao Yuan

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



9.1 Introducing the Wireless Messaging API


Mobile phone network infrastructures provide standard ways to pass text messages between phones. The best known mobile phone messaging protocols include SMS and CBS (Cell Broadcast Short Message Service), both of which work on both Global Systems for Mobile Communications (GSM) and Code Division Multiple Access (CDMA) networks. SMS has become a major source of income for wireless operators; in Europe, SMS services already account for 40 percent of mobile phone carriers' profits. However, because not all J2ME devices are SMS-compatible, the standard J2ME API does not provide a way to access an underlying device's SMS features.

The J2ME WMA specifies a standard set of APIs that J2ME applications running on SMS-enabled devices can use to communicate with network peers via the SMS and CBS protocols. The WMA can be implemented on both the CLDC platform (Connected Limited Device Configuration, for mobile phones and low-end PDAs) and the CDC platform (Connected Device Configuration, for high-end PDAs).

One very important feature of the WMA is that it allows J2ME devices to run SMS-based server applications. You would use an SMS server to automatically process and respond to incoming messages in your J2ME application. Unlike traditional HTTP servers, SMS servers do not rely on the IP network. Server addresses are identified by telephone numbers.

The WMA specification has been developed by the JCP under JSR 120. It is supported by such major phone vendors as Motorola, Siemens, and Nokia, as well as such major mobile network operators as SprintPCS, Cingular, and France Telecom. In this book, we cover WMA v1.0. The WMA v2.0 specification under development by JSR 205 will support Multimedia Messaging Services (MMS).

Since SMS is much more popular than CBS, we focus on SMS messaging here. I first introduce the general concepts of the API and its use. Then, I discuss WMA implementations, particularly the reference implementation that works on PC-based wireless device emulators. Using the reference implementation, I will show you how to implement and run a sample P2P SMS messaging application called WMATester.


9.1.1 Top-Level WMA Classes


Application developers can access WMA features through three top-level interfaces in the javax.wireless.messaging package (Listing 9.1).

Table 9.1. Interfaces in the javax.wireless.messaging Package

Interface

Description

Message

This interface represents a message. The TextMessage and BinaryMessage interfaces are derived from Message and provide more specific message structures.

MessageConnection

This interface represents a network connection for messages. It defines basic methods for sending and receiving messages. For example, the MessageConnection.newMessage() method returns Message instances for outgoing messages; the MessageConnection.receive() method captures synchronously incoming messages.

MessageListener

This interface has only one method: notifyIncomingMessage(). A MessageListener instance is registered with a server MessageConnection. Its notifyIncomingMessage() method is asynchronously invoked when there is an inbound message. The specification requires that the notifyIncomingMessage() return quickly. Thus, it is recommended that you start a new thread to process the inbound message.

Figure 9.1 is a UML diagram illustrating relationships of these interfaces.


Figure 9.1. Top-level WMA interfaces in the javax.wireless.messaging package.



9.1.2 URLs and Message Connections


The GCF connector class javax.microedition.io.Connector instantiates instances of MessageConnection. The URL that is passed to the Connector.open() method determines the connection that will be opened. The following URL patterns and message connection types are supported by the WMA:

The URL sms://+18005555555 specifies a connection to send SMS messages to the phone number 1-800-555-5555. (Note that the WMA has no phone number format requirements; you can use any series of digits that your phone and network will recognize.)

The URL sms://+18005555555:1234 specifies a connection to send SMS messages to port number 1234 at the phone number 1-800-555-5555.

The URL sms://:1234 specifies a server connection to receive messages on port 1234. A server connection can also send messages.

The URL cbs://:3382 specifies a connection that listens for inbound CBS messages on port 3382. Unlike an SMS server connection, this CBS connection cannot send out any message.



SMS Ports


With the WMA, you can specify a port number for each SMS message that you send. If an SMS message is sent to a phone number without a port number, it is interpreted as an inbox message and handled by the receiving phone's native inbox client. No WMA server connection should pick up such inbox messages. WMA peers communicate with each other through pre-agreed private SMS ports.

Now that we understand the basics of the WMA, let's take a look at some concrete code examples.


/ 204